: If you are looping using index integers ( range(len(text)) ), ensure your loop boundaries do not exceed the length of the string.
: Inside the loop, check the current character. You can shift its character code, swap it with a specific partner, or insert random characters between letters.
return ''.join(encoding[ch] for ch in text.upper()) 83 8 create your own encoding codehs answers exclusive
In the CodeHS assignment 8.3.8: Create Your Own Encoding , you are tasked with developing a custom text encoding scheme to represent uppercase letters (A-Z) and the space character using binary. Assignment Requirements Your scheme must be able to represent: Every capital letter A-Z (26 characters). The space character (1 character). Minimal Bits : You must use as few bits as possible for each character. Course Hero Key Logic: Determining the Bit Count To determine how many bits are needed, use the formula 2 to the n-th power is the number of bits. 2 to the fourth power
In a high-tech city called Bit-Opolis, two engineers, Ada and Bo, needed to send messages past a nosy surveillance drone that only recognized standard : If you are looping using index integers
+-------------------------------------------------------+ | 1. Input Aggregation | | (Collect plain text strings from user input) | +-------------------------------------------+-----------+ | v +-------------------------------------------------------+ | 2. Dictionary Mapping | | (Create lookups for letters, spaces, & symbols) | +-------------------------------------------+-----------+ | v +-------------------------------------------------------+ | 3. Fixed-Width Conversions | | (Pad shorter bit segments with leading zeros) | +-------------------------------------------+-----------+ | v +-------------------------------------------------------+ | 4. Sequential Compiling | | (Combine segments into an encoded character stream) | +-------------------------------------------------------+
If you want to minimize the total number of bits, assign shorter binary codes to commonly used letters (like E, T, A) and longer codes to less frequent ones (like Z, Q, X). This is the principle behind . return ''
A standard way to solve this is to assign each character a unique 5-bit binary code starting from Binary Code Encoding Example: "HELLO WORLD"