Hey everyone! So I am working on the off-platform project for the lesson on strings, lesson 7 in the Learn Python 3 course:
https://www.codecademy.com/courses/learn-python-3/informationals/python3-coded-communication
And there is an exercise where we have to code a message to change each letter by the letter which is 10 positions prior in the alphabet. While working on the exercise, it seems like the output letter changes when the input is a lowercase or an uppercase, the uppercase one being wrong. Could someone explain that?
I will write the code and the outputs below:
No uppercase:
alphabet = “abcdefghijklmnopqrstuvwxyz”
punctuation = “., ?! '”
message = “this is starting to get a bit more difficult, i am enjoying it though!”
translated_message = “”
for letter in message:
if not letter in punctuation:
letter_value = alphabet.find(letter)
translated_message += alphabet[(letter_value -10) % 26]
else:
translated_message += letter
print(translated_message)
output:
jxyi yi ijqhjydw je wuj q ryj cehu tyvvyskbj, y qc udzeoydw yj jxekwx!
With uppercase:
alphabet = “abcdefghijklmnopqrstuvwxyz”
punctuation = “., ?! '”
message = “This is starting to get a bit more difficult, I am enjoying it though!”
translated_message = “”
for letter in message:
if not letter in punctuation:
letter_value = alphabet.find(letter)
translated_message += alphabet[(letter_value -10) % 26]
else:
translated_message += letter
print(translated_message)
output:
pxyi yi ijqhjydw je wuj q ryj cehu tyvvyskbj, p qc udzeoydw yj jxekwx!
You can see the first letter changes, as well as the first one after the comma.
Is there an explanation to this? Does Python read a different value for the capital letter?
Thanks!