python - 为什么我在解密程序中收到有关字符串的错误?
问题描述
我正在尝试制作某种解密器。该程序要求您输入一个短语,它会解密它。例如,如果我输入“hi”,它应该显示为“ef”。但是,我得到的只是一个错误,TypeError: unsupported operand type(s) for -: 'str' and 'str'
我不知道该怎么做,我试过摆弄代码但没有好的结果。
def plainText(string):
cipher = ''
for i in string:
if i == ' ':
cipher = cipher - i
elif i.isupper():
cipher = cipher + chr((ord(i) - 3 - 65) % 26 + 65)
else:
cipher = cipher + chr((ord(i) - 3 - 97) % 26 + 97)
return cipher
message = input("What's your message?")
print("Your decrypted message is: ", plainText(message))
print("Your original message was: ", message)```
Again, the error was
TypeError: unsupported operand type(s) for -: 'str' and 'str' at line 7.
Thank you in advance!
解决方案
推荐阅读
- sql - 我们可以在 SQL 中创建主键顺序无关紧要的表吗?
- r - Docker 错误无法分配大小为 1.5gb R 脚本的向量
- javascript - 带有调用/应用/绑定的箭头函数
- cookies - JS 中的 IdentityServer4 自定义 UI
- sql - 在 bigquery 中查询从分区表创建的视图
- angular - Angular:reportProgress 不会逐步返回数据
- parent-child - 在巴比伦 js 的面板中加载 GLTF 模型
- node.js - 在 SQLite3 中获取数据库行时,Row 是 [object Object]
- sql - 插入默认值的 SQL 查询
- flutter - 如何更改应用栏颤动上文本和图标的颜色