2
hello to everyone I want to develop a script that replaces one typed letter with another, so it would look like a = and , b = f .
I spent some time trying to create an algorithm for this function but the interpreter only replaces a letter at once , in case I would like to do this for the whole sentence.
y = []
x = raw_input('reading: ')
print(x)
for i in x:
if (x) == 'a':
x = str('e')
y.append(str('e'[0]))
if (x) == 'b':
x = str('f')
y.append(str('f'[1]))
if (x) == 'c':
x = 'g'
y.append(x[2])
if (x) == 'd':
x = 'h'
y.append(x[3])
if x == 'e':
above a piece of code. I know there are better ways but I’m still beginner .. I was in doubt about using while or for , I ask you to guide me.
You can use dictionaries to associate each letter.. It would look : { "a":" and" , "b" : "f" ...} .. Ai then just turn the typed string into a list and for each element get the corresponding in the dictionary.. Transforming again..
– Marlysson
Your if commands are wrongly chained. Study the Else clause.
– Anonimo