I'm learning Python 3 at the moment, so to test the skills I've learned, I am trying the puzzles at Python Challenge.
I've created some code to solve the 2nd puzzle here. it works, but I think that the way I've done it is very convoluted. Any suggestions on how to solve the puzzle in a simpler way?
(The code basically needs to substitute each letter in a message to the letter 2 spaces to the right of it, such as E->G.)
import string
alphabet = string.ascii_lowercase
letter=0
replaceLetter = 2
times=1
message = input()
newMessage=''
while times < 26:
newMessage = message.replace(alphabet[letter], str(replaceLetter)+',')
message = newMessage
letter = letter + 1
replaceLetter = replaceLetter + 1
time = times + 1
if letter == 26:
times = 0
break
newMessage = message.replace('26'+',', 'a')
message = newMessage
newMessage = message.replace('27'+',', 'b')
message = newMessage
number = 25
message = newMessage
while times < 26:
newMessage = message.replace(str(number)+',', str(alphabet[number]))
message = newMessage
letter = letter + 1
number = number - 1
time = times + 1
if number == -1:
times = 0
break
print(newMessage)