import sys
import string
array = []
while True:
input = raw_input("Please enter no more than 10 characters, one per line, and terminate the message by entering % ")
def main():
key = 3
message = input
cryptMessage = ""
for ch in message:
cryptMessage = cryptMessage + chr(ord(ch) + key)
if input == "%"
print array, len(array), "The coded message is:", cryptMessage
sys.exit(1) #This tells the program to exit
array.append(input)
main()
基本上,除了以加密的形式打印用户输入的文本外,我所有的东西都按我所希望的方式工作。它已经以常规格式打印了,我希望它以常规格式和加密格式打印。它一直说打印行中的cryptMessage变量未定义。我以为我已经在上面的代码中定义了它,但显然不是。我错过了什么?你知道吗
我重新编写了你的代码。出现未定义变量错误的原因是,您在
main()
函数中定义了cryptMessage
,并且在该函数之外无法访问它。你知道吗输出:
相关问题 更多 >
编程相关推荐