我正在研究python,试图制作一个Caeser密码程序。 所以我做了一个GUI平台,能够让密码部分正常工作,但它只能以ASCII格式输出消息。你知道吗
当你运行我的程序时,它会获取信息,你说你想让字母表移动的字母数,然后用ASCII表示信息,我怎么才能让这部分以字母形式出现呢?你知道吗
我尝试将for循环存储到一个变量中,然后将该变量添加到一个常见的ascii-->;字符转换器中,但这不起作用。你知道吗
这是我的密码:
def encode(userPhrase):
msg = input('Enter your message: ')
key = eval(input("enter a number"))
finalmsg = msg.upper()
for ch in finalmsg:
print( str( ord(ch)+key ), end=' ')
你需要让字母表末尾的字母环绕到A,B,C。。。您可以使用模运算(复杂)来完成,或者参见下面的示例
使用
chr
而不是str
。传递一个参数userPhrase
,然后要求输入一条消息。另外,我建议使用int
而不是eval
。你知道吗最后一个问题是非字母(例如空格等)
将
str
更改为chr
:根据chr上的文档:
相关问题 更多 >
编程相关推荐