我正在使用 Python 3 制作我的第一个 Python 程序,但由于某种原因它给了我一个错误
I'm making my first Python program using Python 3 but for some reason it gives me an error
我想在编写程序的过程中测试我的程序,但由于某种原因无法启动
代码:
def main():
menu()
def menu():
print("1.Login\n2.Register\n\n1.Help")
input = int(input("Enter the corresponding number to the action you would like executed: "))
if input==3:
help()
if input==2:
register()
if input==1:
login()
def help():
print("\nIf you enter the number ONE (1) You will be prompted to login to the system\nIf you enter the number TWO (2) you will be prompted to register, so you can login")
def register():
usernameR = input("Enter your username: ")
with open("usernamesR.txt","wt") as output:
output.write(usernameR)
print("Your username is: "+usernameR)
passwordR = str(input("\nEnter your password: "))
with open("passwordsR.txt","wt") as output:
output.write(passwordR)
print("Your password is: "+passwordR)
def login():
print("")
if __name__=="__main__":
main()
这是我得到的错误:
1.Login
回溯(最近调用最后):
2.Register
文件 "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py",第 30 行,位于
主要()
1.Help
文件 "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py",第 2 行,在 main
中
菜单()
文件 "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py",第 5 行,在菜单中
输入 = int(输入("Enter the corresponding number to the action you would like executed: "))
UnboundLocalError: 局部变量 'input' 在赋值前被引用
您的变量名 input
与内置方法 input
冲突。编译器感到困惑,认为 input()
调用正在调用您的本地绑定变量,然后抱怨您尚未定义它。将变量名称更改为 user_input
应该可以解决此问题。
input()
ins in in build function,
在代码中你给变量命名为input
,给不同的变量名.
def menu():
print("1.Login\n2.Register\n\n1.Help")
input = int(input("Enter the corresponding number to the action you would like executed: "))
# ^^^^
我想在编写程序的过程中测试我的程序,但由于某种原因无法启动
代码:
def main():
menu()
def menu():
print("1.Login\n2.Register\n\n1.Help")
input = int(input("Enter the corresponding number to the action you would like executed: "))
if input==3:
help()
if input==2:
register()
if input==1:
login()
def help():
print("\nIf you enter the number ONE (1) You will be prompted to login to the system\nIf you enter the number TWO (2) you will be prompted to register, so you can login")
def register():
usernameR = input("Enter your username: ")
with open("usernamesR.txt","wt") as output:
output.write(usernameR)
print("Your username is: "+usernameR)
passwordR = str(input("\nEnter your password: "))
with open("passwordsR.txt","wt") as output:
output.write(passwordR)
print("Your password is: "+passwordR)
def login():
print("")
if __name__=="__main__":
main()
这是我得到的错误:
1.Login
回溯(最近调用最后):
2.Register
文件 "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py",第 30 行,位于 主要()
1.Help
文件 "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py",第 2 行,在 main
中菜单()
文件 "C:/Users/Joseph/PycharmProjects/LearningPython/Login_System.py",第 5 行,在菜单中 输入 = int(输入("Enter the corresponding number to the action you would like executed: "))
UnboundLocalError: 局部变量 'input' 在赋值前被引用
您的变量名 input
与内置方法 input
冲突。编译器感到困惑,认为 input()
调用正在调用您的本地绑定变量,然后抱怨您尚未定义它。将变量名称更改为 user_input
应该可以解决此问题。
input()
ins in in build function,
在代码中你给变量命名为input
,给不同的变量名.
def menu():
print("1.Login\n2.Register\n\n1.Help")
input = int(input("Enter the corresponding number to the action you would like executed: "))
# ^^^^