2017-10-06 93 views
0

我在学习了有关C编程基础知识的python3后, 但现在我已经卡住了凯撒形式CS50。虽然没有使用cs50库。caesar python 3将字符串部分转换为ascii代码时的语法错误,计算新字符并将其转换回加密文本

所以我已经做了以下内容:

代码:

print('ciphertext: ') 

key = sys.argv[1] 

for i in range(len(plain[i]) 

    if ord(plain[i]) > 64 and ord(plain[i]) < 91 or ord(plain[i]) > 96 and 
    ord(plain[i]) < 123 

     ciphertext = chr(ord (plain[i]) + key %26) 

print('ciphertext: {}'.format(ciphertext)) 

我得到第6行语法代码,其中的密文变成了蓝色。 有人可以告诉我,当我想从中获取加密文本时,我做错了什么。在这个代码上面我定义了纯文本。

回答

0

有在你的代码 几打的语法错误这里固定为您 尝试进行检讨

import sys 
print('ciphertext: ') 

key = sys.argv[1] 

for i in range(len(plain[i])): 
if ord(plain[i]) > 64 and ord(plain[i]) < 91 and ord(plain[i]) > 96 and ord(plain[i]) < 123: 

     ciphertext = chr(ord (plain[i]) + key %26) 

print('ciphertext: {}'.format(ciphertext)) 
+0

感谢您的帮助确实忘了第二个括号。 –