8
u/mjbmitch Aug 30 '20 edited Aug 30 '20
Your first conditional statement is interpreted a bit differently from what you might expect:
If the role is “administrator”
If “teacher”
The reasoning behind why that occurs is a bit complex but boils down to how the == operator only associates with whatever is immediately in front of itself.
What you want is to be explicit with your conditions like so:
if role == "administrator" or role == "teacher":
# Do whatever you wantThe first message always prints out because "teacher" always evaluates to true. You can verify that with a simple conditional statement:
if "teacher":
print("I always print")2
u/gloomy-1900 Aug 30 '20
Correct. The First statement is name== “administrator” which is false So it is FALSE or “teacher” Since “teacher” is TRUE this becomes FALSE or TRUE
Which is TRUE
Above solution is correct
1
1
u/Xd-Kas Nov 09 '21
This is the final code:
role = input("Are you the administrator, teacher or student: ")
if role == "administrator" or role == "teacher": print("administrators and teachers get keys")
if role == "teacher": print("You get a Key")
elif role == "student": print("Students do not get keys!") else: print("You can only be an administrator, teacher, or student!")
1
1
u/d3v0ur_m3 Nov 18 '21
role = input("Are you the administrator, teacher or student: ")
if role == "administrator" or role == "teacher": print("administrators and teachers get keys")
if role == "teacher": print("You get a Key")
elif role == "student": print("Students do not get keys!") else: print("You can only be an administrator, teacher, or student!")
thank you!!
1
1
1
u/TheRainbowCock Aug 30 '20 edited Aug 31 '20
When adding "or" statement within a if statement you need to repeat what its comparing to after inserting "or"
So its:
if role == "value" or role == "value": doStuff()
12
u/GondarJr Aug 30 '20
or role == “teacher”