You iterate over a list of characters, and i is a character. Then you try to save this back to data using the i character as an index. This will not work.
Use enumerate() to get indexes and values:
def shifttext(shift): input=raw_input('Input text here: ') data = list(input) for i, char in enumerate(data): data[i] = chr((ord(char) + shift) % 26) output = ''.join(data) return output
You can simplify this with a generator expression:
def shifttext(shift): input=raw_input('Input text here: ') return ''.join(chr((ord(char) + shift) % 26) for char in input)
But now you will notice that your % 26 will not work; ASCII code points begin after 26:
>>> ord('a') 97
You need to use ord('a') to use the module; Subtraction puts your values ββin the range of 0-25, and you add them again:
a = ord('a') return ''.join(chr((ord(char) - a + shift) % 26) + a) for char in input)
but this will only work for lowercase letters; which may be fine, but you can force it by lower input input:
a = ord('a') return ''.join(chr((ord(char) - a + shift) % 26 + a) for char in input.lower())
If we then proceed to the request to exit the function in order to focus it on doing one job, it will look like this:
def shifttext(text, shift): a = ord('a') return ''.join(chr((ord(char) - a + shift) % 26 + a) for char in text.lower()) print shifttext(raw_input('Input text here: '), 3)
and using this in the online tooltip, I see:
>>> print shifttext(raw_input('Input text here: '), 3) Input text here: Cesarsalad! fhvduvdodgr
Of course, punctuation is now taken. Last revision, now only letter offset:
def shifttext(text, shift): a = ord('a') return ''.join( chr((ord(char) - a + shift) % 26 + a) if 'a' <= char <= 'z' else char for char in text.lower())
and get:
>>> print shifttext(raw_input('Input text here: '), 3) Input text here: Ceasarsalad! fhdvduvdodg!