: For each character, look up its encoded value in your dictionary and append it to a new result string. 💻 Sample Solution (Python)
def encode(message): """ Encodes a string into a list of integers using a custom shift cipher. Each character is converted to its ASCII code, then shifted by +5. """ encoded_list = [] for ch in message: # Custom rule: shift ASCII value by 5 encoded_value = ord(ch) + 5 encoded_list.append(encoded_value) return encoded_list
Make sure you use the input() function to let the grader or user test different phrases.
CodeHS is the culmination of a series of exercises that introduce the fundamental ways computers represent text as binary data. The module typically covers: 8.3 8 create your own encoding codehs answers
# 1. Get input from the user secret_message = input("Enter a message to encode: ") encoded_message = "" # 2. Loop through every character for char in secret_message: # 3. Apply substitution logic if char.lower() == 'a': encoded_message += "4" elif char.lower() == 'e': encoded_message += "3" elif char.lower() == 'i': encoded_message += "1" elif char.lower() == 'o': encoded_message += "0" elif char.lower() == 'u': encoded_message += "7" else: # Keep non-vowels the same encoded_message += char # 4. Print the final encoded string print("Encoded message: " + encoded_message) Use code with caution. Debugging & Passing CodeHS Autograders
Inside the loop, determine how you want to alter the characters. A simple yet effective rule adds a fixed integer value to the ASCII code of each character. Complete Code Solution
A (65) and a (97) have different character codes. Ensure your shift logic works for both uppercase and lowercase. : For each character, look up its encoded
: Initialized at i = 0 , it runs as long as i is less than text.length . This guarantees every single character is checked.
In the CodeHS exercise 8.3.8: Create Your Own Encoding , the goal is to practice using dictionaries
Here is a breakdown of how to build this "Encoding" program and a sample solution. The Concept """ encoded_list = [] for ch in message:
Always name your primary string manipulation function exactly as requested by the prompt instructions.
: Updates the result string step-by-step before returning it to the main start() function. Python Solution: 8.3.8 Create Your Own Encoding
This assignment is more than a programming exercise; it teaches critical computer‑science concepts: