I'm new to Python and thought I'd try to make a Caesar cipher and could use some help with my code. It looks like this:
def cipher(input): input = input.lower() #don't mind capital letters output = [] alphabet = 'abcdefghijklmnopqrstuvwxyz' steps = int(raw_input('How many steps? >> ')) for i in input: if i == ' ': #for space output.append(' ') else: pos = alphabet.index(i) + steps if pos >= 25: #for out-of-range pos -= 26 output.append(alphabet[pos]) print 'The ciphered message: ', ''.join(output) input = raw_input('Write your message. >> ') cipher(input) It seems to work a bit, but not fully, when it comes to spaces.
This is what I get:
Write your message. >> abc abc How many steps? >> 1 The ciphered message: bcd dbcd I don't quite understand where the extra letter (d, in this case) in the output comes from.
Thankful for any help.
'abc[...]xyz'. Just usestring.ascii_lowercase.