【发布时间】:2018-12-17 13:16:06
【问题描述】:
- 我决定制作某种密码用于测试 Unicode。
- 我已经通过在 Unicode 中添加数字来做到这一点,所以这将是一种秘密。
- 我一直收到此错误,但我不知道如何解决。
- 有什么解决办法吗?
原码
message = input("Enter a message you want to be revealed: ")
secret_string = ""
for char in message:
secret_string += str(chr(char + 7429146))
print("Revealed", secret_string)
q = input("")
原始错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-182-49ece294a581> in <module>
2 secret_string = ""
3 for char in message:
----> 4 secret_string += str(chr(char + 7429146))
5 print("Revealed", secret_string)
6 q = input("")
TypeError: can only concatenate str (not "int") to str
更新代码
while True:
try:
message = int(input("Enter a message you want to be decrypt: "))
break
except ValueError:
print("Error, it must be an integer")
secret_string = ""
for char in message:
secret_string += chr(ord(char - str(742146)))
print("Decrypted", secret_string)
q = input("")
【问题讨论】: