phrase = input("Enter text to Cipher: ")
shift = int(input("Please enter shift: "))
encryption = input("Do you want to [E]ncrypt or [D]ecrypt?: ").upper
new_strs = []
for character in phrase:
x = ord(character)
if encryption == ("E"):
new = x + shift
if encryption == ("D"):
new = x - shift
new_strs.append(chr(new))
print (("").join(new_strs))
代碼有效,只要我沒有「if encryption = E/D」但它不會如果我這樣做。變量'new'沒有定義
這是發生的錯誤消息。
Traceback (most recent call last):
File "C:\Python34\Doc\test.py", line 14, in <module>
new_strs.append(chr(new))
NameError: name 'new' is not defined
嘗試更改爲'upper()'而不是'upper'。這是一個功能。 – mehtunguh