0
Why doesn't my code work?
I'm writing code to write a string in a backwards alphabet (i.e. cat -> xzg) and this is my code: string = input() dict = { 'a': 'z', 'b': 'y', 'c': 'x', 'd': 'w', 'e': 'v', 'f': 'u', 'g': 't', 'h': 's', 'i': 'r', 'j': 'q', 'k': 'p', 'l': 'o', 'm': 'n', 'n': 'm', 'o': 'l', 'p': 'k', 'q': 'j', 'r': 'i', 's': 'h', 't': 'g', 'u': 'f', 'v': 'e', 'w': 'd', 'x': 'c', 'y': 'b', 'z': 'a' } string.lower() for x in string: x = dict[x] print(string) Why does it just spit out the input, and how do I fix it?
3 odpowiedzi
+ 2
https://code.sololearn.com/c2hqp1KvtrKE/?ref=app
This is correct way
+ 2
Your solution doesn’t work for words like ‘huzzah’
+ 1
string = string.replace(x,dict[x])
put this inside the loop