Link to the project:
https://www.codecademy.com/courses/learn-python-3/informationals/python3-coded-communication
I’m stuck on the project: coded correspondence. I have it working when there are only letters in the message, but if I add code to account for punctuation, it doens’t work anymore. What am I doing wrong?
It works with this code:
alfabet = ['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']
def test(message):
list_message = list(message)
empty_decypher = []
for x in range(len(list_message)):
index_alfabet = alfabet.index(list_message[x])
index_decypher = index_alfabet + 10
if index_decypher < 26:
empty_decypher.append(alfabet[index_decypher])
if index_decypher >= 26:
index_around = index_decypher % 26
empty_decypher.append(alfabet[index_around])
return ''.join(empty_decypher)
print(test('xuo'))
My section to account for punctuation is below, but than I get an error because empty_decypher is [0 , 1, 2] and that is not a string to join. I don’t get why this code would give 012. Can somebody explain this to me?
alfabet = ['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']
def decypher(message):
list_message = list(message)
empty_decypher = []
for x in range(len(list_message)):
if x not in alfabet:
empty_decypher.append(x)
if x in alfabet:
index_alfabet = alfabet.index(list_message[x])
index_decypher = index_alfabet + 10
if index_decypher < 26:
empty_decypher.append(alfabet[index_decypher])
if index_decypher >= 26:
index_around = index_decypher % 26
empty_decypher.append(alfabet[index_around])
return ''.join(empty_decypher)
print(decypher('xuo'))