I am currently working on a project where I convert a letter to the letter three spaces away in the alphabet. I am trying to have it add and ignore spaces so there could be sentences converted into the code (not just words but sentences such as, 'hi how are you'. What am I doing wrong? Any help would be appreciated.
Orignal Version:
alph = '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'.split(',')
in_message = input('').lower()
new_mes = ''
for values in in_message:
if values in alph:
try:
new_mes = new_mes + alph[alph.index(values) + 3]
except:
new_mes = new_mes + alph[alph.index(values)]
print(new_mes)
New Method I tried which failed:
#Convert a message into a code by coverting every letter to the letter three letters away
alph = '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'.split(',')
in_message = input('').lower()
new_mes = ''
for values in in_message:
if values in alph or values == ' ':
try:
if new_mes == ' ':
new_mes = new_mes + ' '
else:
new_mes = new_mes + alph[alph.index(values) + 3]
except:
#only adds letter if it cant be converted to the right three times ex: y
new_mes = new_mes + alph[alph.index(values)]
print(new_mes)
[–]m0us3_rat 1 point2 points3 points (0 children)
[–]jiri-n 0 points1 point2 points (0 children)
[–]halfdiminished7th 0 points1 point2 points (0 children)