python - 有没有办法让程序接受大写和非大写的输入?
问题描述
正如标题所说,我的程序使用大写字母运行,但我希望它与非大写字母和大写字母输入兼容。它应该作为大写加密返回。
decrypted = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ.1234567890 "
encrypted = b"SE2RL.1W5A0Z8D7H4B9M6JX3FTNVQGPUOYCKI "
encrypt_table = bytes.maketrans(decrypted, encrypted)
decrypt_table = bytes.maketrans(encrypted, decrypted)
result = ''
choice = ''
message = ''
while choice != 'X':
choice = input("\n Do you want to encrypt or decrypt the message?\n E to encrypt, D to decrypt or X to exit program. ")
if choice == 'E':
message = input('\nEnter message for encryption: ')
result = message.translate(encrypt_table)
print(result + '\n\n')
elif choice == 'D':
message = input('\nEnter message to decrypt: ')
result = message.translate(decrypt_table)
print(result + '\n\n')
elif choice != 'X':
print('You have entered an invalid input, please try again. \n\n')
解决方案
推荐阅读
- javascript - 关闭。为什么在这种情况下要删除“父函数”的词法环境?
- javascript - 从网页版 Firestore 获取数据
- c# - 从字符串数组的末尾删除所有空元素
- python - Django:检查一个模型中的行数小于或等于另一个模型中的值,并且一个字段值限制其他字段
- javascript - puppeteer 没有从网站上抓取完整信息
- ruby - mac中的Ruby gem安装失败
- excel - 复制和粘贴信息时 VBA 代码无法正常工作
- ms-access - 如何防止 SSIS 锁定 ms 访问数据库/表/行?
- python - Julia 与 Python 中的位打包性能
- node.js - 不明白为什么我的异步等待在我的 lambda 函数中不起作用