Hello
So on task 1 i’m already confused
In summary - we have to decode the message, it’s an offset of 10 from the usual alphabet.
So I wrong the first bit of code to create the “offset” list, which all runs fine and is stored as a list in coded_alphabet.
My approach is
For every letter in the coded message, go through the coded_alphabet, find the matching character, then add the character from the normal alphabet at the same index to the decoded_message list.
I am getting an error
File “script.py”, line 30, in
if letter == code[i]:
IndexError: string index out of range
I thought that using the while loop would stop that? I dont know why the index would go above that?
Also, do you think this solution is even going to work?
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z']
coded_alphabet = []
i = 0
for letter in alphabet:
letter = alphabet[i]
if i < 16:
new = i+ 10
code_letter = alphabet[new]
coded_alphabet.append(code_letter)
i+=1
else:
new = i+10-26
code_letter = alphabet[new]
coded_alphabet.append(code_letter)
i+=1
print(coded_alphabet)
coded_message = "xuo jxuhu! jxyi yi qd unqcfbu ev q squiqh syfxuh. muhu oek qrbu je tusetu yj? y xefu ie! iudt cu q cuiiqwu rqsa myjx jxu iqcu evviuj!"
i=0
decoded_message = []
for letter in coded_message:
i= 0
while i <= 26:
for code in coded_alphabet:
if letter == code[i]:
decoded_message.append(alphabet[i])
elif letter == ' ':
decoded_message.append(' ')
else:
i+= 1
print(decoded_message)