为什么第18行出现语法错误?IDE说,print()
函数有问题,但我不知道具体是什么。我将这个程序从C移植到Python,因为我正在学习Python。你知道吗
#caesar encipher
import sys
import cs50
if len(sys.argv)!= 2:
print("Nope")
k = int(sys.argv[1])
if k<0:
print("Nope")
else:
code = cs50.get_string()
#add k letters to each character in the string. For example is code[0]='a' and k=3, program will return 'd'.
for i in code:
if code[i].islower():
new_code = chr((((ord(code[i]+k)- 97)% 26)+ 97)
print(f"{new_code}")
elif code[i].isupper():
new_code = chr((((ord(code[i]+k)- 65)% 26)+ 65)
print(f"{new_code}")
else:
print(code[i])
print()
一定是这样
相关问题 更多 >
编程相关推荐