caesar python 3 syntax-error when converting string parts to ascii code,计算新字符并将其转换回加密文本
caesar python 3 syntax-error when converting string parts to ascii code, calculate the new character and convert it back to encrypted text
在掌握了 C 编程的基础知识后,我正在学校学习 python3。
但现在我已经卡在凯撒表格 cs50 上了。虽然没有使用 cs50 库。
所以我做了以下事情:
代码:
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 行得到一个语法代码,其中密文变为蓝色。
当我想从中获取加密文本时,有人能告诉我我做错了什么吗?在这段代码之上我定义了 plain.
您的代码中有几十个语法错误
在这里为您修复
尝试查看它
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))
在掌握了 C 编程的基础知识后,我正在学校学习 python3。 但现在我已经卡在凯撒表格 cs50 上了。虽然没有使用 cs50 库。
所以我做了以下事情:
代码:
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 行得到一个语法代码,其中密文变为蓝色。 当我想从中获取加密文本时,有人能告诉我我做错了什么吗?在这段代码之上我定义了 plain.
您的代码中有几十个语法错误 在这里为您修复 尝试查看它
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))