83 — 8 Create Your Own Encoding Codehs Answers Exclusive [2021]
def encode(text): text = text.upper() encoded = [] for ch in text: if ch in encode_map: encoded.append(encode_map[ch]) else: encoded.append('?') # handle unknown chars return ' '.join(encoded)
If you can share the from CodeHS (without violating their rules), I can help you reason through the logic without giving the direct answer.
encode_map = 'A': '1', 'B': '2', 'C': '3', 'D': '4', 'E': '5', 'F': '6', 'G': '7', 'H': '8', 'I': '9', 'J': '10', 'K': '11', 'L': '12', 'M': '13', 'N': '14', 'O': '15', 'P': '16', 'Q': '17', 'R': '18', 'S': '19', 'T': '20', 'U': '21', 'V': '22', 'W': '23', 'X': '24', 'Y': '25', 'Z': '26', ' ': '0'
# 自定义编码方案:5-bit 编码表 encoding_table = 'A':'00000', 'B':'00001', 'C':'00010', 'D':'00011', 'E':'00100', 'F':'00101', 'G':'00110', 'H':'00111', 'I':'01000', 'J':'01001', 'K':'01010', 'L':'01011', 'M':'01100', 'N':'01101', 'O':'01110', 'P':'01111', 'Q':'10000', 'R':'10001', 'S':'10010', 'T':'10011', 'U':'10100', 'V':'10101', 'W':'10110', 'X':'10111', 'Y':'11000', 'Z':'11001', ' ':'11010' 83 8 create your own encoding codehs answers exclusive
If the CodeHS problem asks for a , you could:
In real-world applications, letters that appear frequently (like 'E' and 'A') are given shorter binary codes (e.g., 01 ), while rare letters like 'Z' get longer codes (e.g., 111010 ). This reduces the overall size of the encoded file. However, you will need to add a "delimiter" character (like a v or a space) in between your bit packages so your decoder loop knows exactly when to split the string!
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 def encode(text): text = text
I can provide JavaScript code that does this. The user might be looking for the specific answer for the CodeHS exercise, which might expect a certain format. I can also include a Python solution.
To ensure this matches your assignment perfectly, let me know: Are you coding this in or JavaScript ?
Students who truly understand how to build an encoding from scratch are better prepared for these advanced topics. They recognize that encoding is not magic—it is a deliberate, human-designed mapping. However, you will need to add a "delimiter"
This method shifts the Unicode value of each character by a fixed numeric key. For example, a shift of +3 turns "A" into "D".
alphabet = "abcdefghijklmnopqrstuvwxyz " mapping = alphabet[i]: i+1 for i in range(len(alphabet)) reverse_mapping = v: k for k, v in mapping.items()
In this guide, we’ll break down the logic behind the "Create Your Own Encoding" assignment, explain the "exclusive" tricks to making it work, and provide the conceptual answers you need to ace the lab. Understanding the Task: What is Encoding?