gpt4 book ai didi

python - 名称错误 : name '[string]' is not defined

转载 作者:太空宇宙 更新时间:2023-11-04 00:47:21 26 4
gpt4 key购买 nike

<分区>

在测试我的程序时,我不断收到此错误:

1. Encrypt a file
2. Decrypt a file
----> 1
Enter the filename you'd like to encrypt: test
Traceback (most recent call last):
File "./encrypt.py", line 71, in <module>
Main()
File "./encrypt.py", line 58, in Main
filename = input("Enter the filename you'd like to encrypt: ")
File "<string>", line 1, in <module>
NameError: name 'test' is not defined

这是我的 Main() 函数代码:

def Main():
print("1. Encrypt a file")
print("2. Decrypt a file")
choice = str(input("----> "))
if choice == '1':
filename = input("Enter the filename you'd like to encrypt: ")
password = input("Enter a password used for the encryption tool: ")
encrypt(getKey(password), filename)
print("File has been encrypted.")
elif choice == '2':
filename = input("Enter the filename you'd like to decrypt: ")
password = input("Enter the password used for the encryption of this file: ")
decrypt(getKey(password), filename)
print("File has been decrypted. Note that if the password used in the encryption does " \
+ "not match the password you entered in, the file will remain encrypted.")
else:
print("Invalid option. Closing the program...")

我正在使用简单的 input() 方法来获取我的数据(例如“测试”),它会不断告诉我我在运行时输入的任何信息,我刚刚输入的名称没有定义。我没有看到任何格式错误、语法错误等。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com