Code Correspondance Python Project - Extra characters produced - Please help

Hi all,
I have been struggling with the code correspondacne project and managed to get very nearly there on the first question. However my code appears to be returning extra characters and i dont know why!!

If any one can help me understand what is going on and why that would be so so amazing.

Link to project:

My current code and the values it returns are below:

My code:

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!" punctuation="!.? " alphabet = "abcdefghijklmnopqrstuvwxyz" de_coded_list = [] coded_list = [] for letter in coded_message: if letter not in punctuation: letter_index = alphabet.find(letter) code_index = letter_index + 10 if code_index < len(alphabet): code_index = code_index elif code_index>=len(alphabet): code_index = code_index - 26 else: None else: de_coded_list.append(letter) coded_list.append(letter) de_coded_list.append(alphabet[code_index]) coded_list.append(alphabet[letter_index]) print("The length of the coded message is "+str(len(coded_message))+" characters.") print("The length of the de-coded message is "+str(len(de_coded_list))+" characters.") de_coded_string = ''.join(de_coded_list) print(de_coded_string) print(coded_list)

Returned output:
The length of the coded message is 133 characters.
The length of the de-coded message is 165 characters.
hey ythere!e ethis sis san nexample eof fa acaesar rcipher.r rwere eyou uable eto odecode eit?t ti ihope eso!o osend dme ea amessage eback kwith hthe esame eoffset!t
[‘x’, ‘u’, ‘o’, ’ ', ‘o’, ‘j’, ‘x’, ‘u’, ‘h’, ‘u’, ‘!’, ‘u’, ’ ', ‘u’, ‘j’, ‘x’, ‘y’, ‘i’, ’ ', ‘i’, ‘y’, ‘i’, ’ ', ‘i’, ‘q’, ‘d’, ’ ', ‘d’, ‘u’, ‘n’, ‘q’, ‘c’, ‘f’, ‘b’, ‘u’, ’ ', ‘u’, ‘e’, ‘v’, ’ ', ‘v’, ‘q’, ’ ', ‘q’, ‘s’, ‘q’, ‘u’, ‘i’, ‘q’, ‘h’, ’ ', ‘h’, ‘s’, ‘y’, ‘f’, ‘x’, ‘u’, ‘h’, ‘.’, ‘h’, ’ ', ‘h’, ‘m’, ‘u’, ‘h’, ‘u’, ’ ', ‘u’, ‘o’, ‘e’, ‘k’, ’ ', ‘k’, ‘q’, ‘r’, ‘b’, ‘u’, ’ ', ‘u’, ‘j’, ‘e’, ’ ', ‘e’, ‘t’, ‘u’, ‘s’, ‘e’, ‘t’, ‘u’, ’ ', ‘u’, ‘y’, ‘j’, ‘?’, ‘j’, ’ ', ‘j’, ‘y’, ’ ', ‘y’, ‘x’, ‘e’, ‘f’, ‘u’, ’ ', ‘u’, ‘i’, ‘e’, ‘!’, ‘e’, ’ ', ‘e’, ‘i’, ‘u’, ‘d’, ‘t’, ’ ', ‘t’, ‘c’, ‘u’, ’ ', ‘u’, ‘q’, ’ ', ‘q’, ‘c’, ‘u’, ‘i’, ‘i’, ‘q’, ‘w’, ‘u’, ’ ', ‘u’, ‘r’, ‘q’, ‘s’, ‘a’, ’ ', ‘a’, ‘m’, ‘y’, ‘j’, ‘x’, ’ ', ‘x’, ‘j’, ‘x’, ‘u’, ’ ', ‘u’, ‘i’, ‘q’, ‘c’, ‘u’, ’ ', ‘u’, ‘e’, ‘v’, ‘v’, ‘i’, ‘u’, ‘j’, ‘!’, ‘j’]

Do you recognize a pattern in the decoded message regarding the extra characters?


yes, it appears to be that after every punctuation/ space the letter before is repeated before the message resumes.
I dont currently understand why though.

Ahh! I understand what you were drawing my attention to:
My .append() statements were in the wrong place and so were still being triggered for the previous character after the characters in the punctuation list were append-ed.

Thank you very much!!


Good work! :+1: