无法使用输入菜单访问代码内的功能
Can't access the functions inside the code with the input menu
我无法访问输入菜单中其余代码中的功能
用户应该输入一个字母,该字母会将他带到程序的功能并继续按照功能状态进行编辑,但我收到一条错误消息,指出“NameError:name 'reg_user' is not defined”。
def display_menu_options():
global menu_options
menu_options = input('''Please select one of the following options:
a - Adding a task
va - View all tasks
vm - View my tasks
e - Exit
:''').lower()
if menu_options == "a":
add_task()
elif menu_options == "va":
view_all()
elif menu_options == "vm":
view_mine()
elif menu_options == "e":
print("Goodbye!")
else:
print("You have made a wrong choice, Please Try again")
return menu_options
def display_admin_menu_options():
global menu_options
menu_options = input('''Please enter one of the following options:
r - register user
a - add task
va- view all tasks
vm - view my tasks
gr - generate reports
ds - display statistics
e - exit
:''').lower()
if menu_options == "r":
reg_user()
elif menu_options == "a":
add_task()
elif menu_options == "va":
view_all()
elif menu_options == "vm":
view_mine()
elif menu_options == "gr":
generate_reports()
elif menu_options == "ds":
all_statistics()
elif menu_options == "e":
print("Goodbye!")
else:
print("You have made a wrong choice, Please Try again")
return menu_options
def login():
username = input("Enter your username: ")
password = input("Enter your password: ")
for line in open('user.txt', 'r').readlines():
field = line.strip().split(", ")
if username == field[0] and password == field[1]:
print('Welcome' + username)
return True, field[0] == "admin"
return False, False
login_success, is_admin = login()
if login_success and is_admin:
display_admin_menu_options()
elif login_success:
display_menu_options()
else:
print("Username or password incorrect!")
我假设您正在执行并将其编写为脚本。因此,您正在调用该函数,并在定义您尝试访问的函数的下方。这些不是“定义的”,因为代码是解释的而不是编译的。将所有函数定义置于 login() 调用之上
我无法访问输入菜单中其余代码中的功能 用户应该输入一个字母,该字母会将他带到程序的功能并继续按照功能状态进行编辑,但我收到一条错误消息,指出“NameError:name 'reg_user' is not defined”。
def display_menu_options():
global menu_options
menu_options = input('''Please select one of the following options:
a - Adding a task
va - View all tasks
vm - View my tasks
e - Exit
:''').lower()
if menu_options == "a":
add_task()
elif menu_options == "va":
view_all()
elif menu_options == "vm":
view_mine()
elif menu_options == "e":
print("Goodbye!")
else:
print("You have made a wrong choice, Please Try again")
return menu_options
def display_admin_menu_options():
global menu_options
menu_options = input('''Please enter one of the following options:
r - register user
a - add task
va- view all tasks
vm - view my tasks
gr - generate reports
ds - display statistics
e - exit
:''').lower()
if menu_options == "r":
reg_user()
elif menu_options == "a":
add_task()
elif menu_options == "va":
view_all()
elif menu_options == "vm":
view_mine()
elif menu_options == "gr":
generate_reports()
elif menu_options == "ds":
all_statistics()
elif menu_options == "e":
print("Goodbye!")
else:
print("You have made a wrong choice, Please Try again")
return menu_options
def login():
username = input("Enter your username: ")
password = input("Enter your password: ")
for line in open('user.txt', 'r').readlines():
field = line.strip().split(", ")
if username == field[0] and password == field[1]:
print('Welcome' + username)
return True, field[0] == "admin"
return False, False
login_success, is_admin = login()
if login_success and is_admin:
display_admin_menu_options()
elif login_success:
display_menu_options()
else:
print("Username or password incorrect!")
我假设您正在执行并将其编写为脚本。因此,您正在调用该函数,并在定义您尝试访问的函数的下方。这些不是“定义的”,因为代码是解释的而不是编译的。将所有函数定义置于 login() 调用之上