mercredi 24 janvier 2018

Python 2.7.4, does anyone know why this is not working?

The following code is for one of my excercises to pass the subject,

This is my code:

rot13=raw_input("Please write your text! ")

This is where i ask the user for a text

for i in range(len(rot13)):

And in this part I check the text letter by letter with for.

 if rot13[i]=="a":
     rot13[i]="n"
 elif rot13[i]=="b":
     rot13[i]="o"
 elif rot13[i]=="c":
     rot13[i]="p"
 elif rot13[i]=="d":
     rot13[i]="q"
 elif rot13[i]=="e":
     rot13[i]="r"
 elif rot13[i]=="f":
     rot13[i]="s"
 elif rot13[i]=="g":
     rot13[i]="t"
 elif rot13[i]=="h":
     rot13[i]="u"
 elif rot13[i]=="i":
     rot13[i]="v"
 elif rot13[i]=="j":
     rot13[i]="w"
 elif rot13[i]=="k":
     rot13[i]="x"
 elif rot13[i]=="l":
     rot13[i]="y"
 elif rot13[i]=="m":
     rot13[i]="z"
 elif rot13[i]=="n":
     rot13[i]="a"
 elif rot13[i]=="o":
     rot13[i]="b"
 elif rot13[i]=="p":
     rot13[i]="c"
 elif rot13[i]=="q":
     rot13[i]="d"
 elif rot13[i]=="r":
     rot13[i]="e"
 elif rot13[i]=="s":
     rot13[i]="f"
 elif rot13[i]=="t":
     rot13[i]="g"
 elif rot13[i]=="u":
     rot13[i]="h"
 elif rot13[i]=="v":
     rot13[i]="i"
 elif rot13[i]=="w":
     rot13[i]="j"
 elif rot13[i]=="x":
     rot13[i]="k"
 elif rot13[i]=="y":
     rot13[i]="l"
 elif rot13[i]=="z":
     rot13[i]="m" 

print rot13

Does anyone knows why this is not working?

I do not want to do it with encode.

Aucun commentaire:

Enregistrer un commentaire