我刚开始学习编程,会有愚蠢的问题。我使用字典制作了 ROT-13,但后来我决定使用字符串而不是字典。但是问题来了:
ROT_13 = "abcdefghijklmnopqrstuvwxyz"
text_input = input("Enter your text: ")
text_output = ""
for i in text_input:
text_output = text_output + ROT_13[i+13]
print (text_output)
那是怎么回事:
Traceback (most recent call last):
File "D:/programming/challenges/challenge_61.py", line 5, in <module>
text_output = text_output + ROT_13[i+13]
TypeError: must be str, not int
那么,有什么解决办法吗?还是更好地使用字典而不是字符串?