The Spy Life help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The Spy Life help

I'm dumb in Python, but why is this not working? symbols = ["!", "@", "#", "

quot;, "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", ":", ";", "[", "]", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] str = input() for i in symbols: str.replace(symbols[i], "") print(str[::-1]) Is something wrong?

10th May 2020, 1:32 AM
Epsilon ︻╦̵̵͇̿̿̿̿╤──
Epsilon ︻╦̵̵͇̿̿̿̿╤── - avatar
2 Answers
+ 6
"for i in symbols:" iterates over the list values. Use "for i in range(len(symbols)):" to iterate over indexes. Check Rithea Sreng answer for more on this. Replace doesn't change the original string. It returns a modified copy of that string: str = str.replace( ... ) 2nd case is not solved yet but it isn't hidden. You'll find the reason by yourself. Avoid using built-in classes, functions, etc as variable names. For example str names the string data-type built-in class. Use a different identifier.
10th May 2020, 2:09 AM
Kevin ★
+ 1
I do not know but I think it is more complex no easy so it is easier to make errors. Make easy I think is the solution
13th Nov 2022, 2:27 PM
Giuseppe Noce
Giuseppe Noce - avatar