Skip to main content

8.3 8 Create Your Own Encoding Codehs Answers -

DECODING = code: char for char, code in ENCODING.items()

Automated unit tests on CodeHS look for exact parameter matching. If your phrase utilizes uppercase characters ( HELLO ), make sure your dictionary explicitly contains uppercase character parameters rather than lowercase options.

To build this program successfully without breaking the CodeHS autograder, your code must follow a strict, logical sequence:

Inside the loop, check if the current character str.charAt(i) matches the next character str.charAt(i + 1) . Increment or Commit: If they match, add 1 to your counter. 8.3 8 create your own encoding codehs answers

You’ll need one dictionary for encoding and another for decoding, or a single dictionary and then reverse it for decoding.

Once the loop finishes, print the completed string. Code Implementation (JavaScript / CodeHS Sandbox)

Need more help? Check the CodeHS documentation on dictionaries or ask your instructor for clarification on the specific requirements of your version of 8.3.8. DECODING = code: char for char, code in ENCODING

def encode(s): mapping = 'a':1, 'b':2, 'c':3, ' ':0 return [mapping[ch] for ch in s]

Alternatively, you can create a (Huffman‑style) scheme, where the most common characters get the shortest codes. For example:

. This is the smallest number of bits that can represent all 26 letters plus a space. Create the Character Map Assign a unique 5-bit string to every character. right arrow right arrow right arrow Encode the Required Phrase ("HELLO WORLD") Increment or Commit: If they match, add 1 to your counter

Is it a letter, a number, or a space?

The goal is to create a function that substitutes characters for binary values, similar to how Morse code uses dots and dashes . The Solution Strategy

print(f"Plain Text: plain_text") print(f"Encoded Text: encoded") print(f"Decoded Text: decoded")