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變量是未定義的。我以爲我已經在上面的代碼中定義了它,但顯然不是。我錯過了什麼?ceaser密碼中未定義的變量-Python
你'高清的main():'在while循環?另請確定遊覽縮進。 – Marcin 2015-02-12 02:09:25
我會修正縮進,但我仍然不知道爲什麼cryptMessage是未定義的。我以前只運行過加密部分,並沒有得到那個錯誤。 – 2015-02-12 02:23:15
這裏沒有正確的縮進,它很難理解你的程序應該如何表現。在Python中,縮進對正確執行至關重要。沒有這個,它很難在代碼spinet中看到任何結構/邏輯。 – Marcin 2015-02-12 02:26:17