x = input('Please Enter a Sentence: ')
y = input('Please Enter a Number: ')
y = int(y)
g = list(x)
j = ['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']
limit = 25
for e in g:
q = j.index(e)
if (q+y) > 25:
oman = (q+y) % 26
newg = j[oman]
print(newg, end="")
elif (q+y) <= 25:
newg = j[q+y]
print(newg, end="")
I have to write a Caesar cipher for homework in python. (A caesar cipher shifts letters in phrase in order to decipher something.)
My program is supposed to take a sentence as and a number as input and shift each letter in the sentence by the input number. It works for phrases with no spaces, but I need it to work with spaces. Also, the program does not need to account for punctuation.
If anyone could give me some pointers on how to do this that would be very helpful.
I tried putting a space item in the alphabet variable but then the shift is off.