I have this code I want it to ask the question as many times as it needs to until a yes or no answer is given
def teacheraskno():
teacher = input("Are you a teacher? yes and no answers only! > ")
if teacher == "no" or "yes".lower():
if teacher == "no".lower():
start()
if teacher == "yes".lower():
teacheraskyes()
else:
print ("Please enter yes and no answers only!")
teacheraskno()
def teacheraskyes():
if teacher == "yes".lower():
password = input("What is the Password? > ")
if password =="123".lower():
print ("ACCESS GRANTED!")
classname = input("what class would you like to view? 1, 2 or 3 > ")
f = open(classname + ".txt", 'r') #opens the class file
file_contents = f.read()
print (file_contents)
f.close()
teacher = input("Are you a teacher? yes and no answers only! > ")
if teacher == "no" or "yes".lower():
if teacher == "no".lower():
start()
if teacher == "yes".lower():
teacheraskyes()
else:
print ("Please enter yes and no answers only!")
teacheraskno()
I keep getting this error
==============================Math Revision Quiz================================
Are you a teacher? yes and no answers only! > bla
Please enter yes and no answers only!
Are you a teacher? yes and no answers only! > yes
Traceback (most recent call last):
File "S:\My Documents\Ben Atia CA A453\Python Code\Python Code 1.py", line 142, in <module>
teacheraskno()
File "S:\My Documents\Ben Atia CA A453\Python Code\Python Code 1.py", line 118, in teacheraskno
teacheraskyes()
File "S:\My Documents\Ben Atia CA A453\Python Code\Python Code 1.py", line 125, in teacheraskyes
if password =="123".lower(): #if the password is correct it will let the teacher view the code
UnboundLocalError: local variable 'password' referenced before assignment
>>>
What does this error mean and how can I fix it?
Please help me to solve this problem.
teacher.lower()instead of"yes".lower()or"no".lower()."no"and"yes"are already lowercase... Also you should compare like thisteacher.lower() == "yes" or teacher.lower() == "no"123as password and please don't hard-code it! :-/