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?

2nd Nov 2022, 2:14 PM
Matt
3 Respostas
2nd Nov 2022, 3:17 PM
Random
Random - avatar
+ 2
Your solution doesn’t work for words like ‘huzzah’
2nd Nov 2022, 3:07 PM
Matt
+ 1
string = string.replace(x,dict[x]) put this inside the loop
2nd Nov 2022, 2:21 PM
Random
Random - avatar