У меня есть этот код, который я хочу, чтобы задать вопрос, как столько раз, сколько это необходимо, чтобы до тех пор, да или нет ответа даетсякод ошибки Python при использовании функции
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()
Я получаю эту ошибку
==============================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
>>>
Что означает эта ошибка и как ее исправить?
Пожалуйста, помогите мне решить эту проблему.
Вы должны использовать 'teacher.lower()' вместо '' yes '.lower() 'или' "no" .lower() '. '' no "' и '' yes "' уже имеют строчные значения ... Также вы должны сравнить это: 'teacher.lower() ==" yes "или teacher.lower() ==" no "' –
Пожалуйста не используйте '123' в качестве пароля и, пожалуйста, не жёстко его кодируйте! : -/ –
Отформатируйте свой код и трассировку. –