-1

Help, whenever I type in an more than one or statements in a program, it will only run the first line of them, what is the problem?

if foo == "ADMIN" or "1":
    os.system("cls")
    global CODES
    CODES = "BLUE"
    PORTABLENESS()
elif foo == "IT" or "2":
    os.system("cls")
    global CODE
    CODES = "Green"
    PORTABLENESS()
elif foo == "STUDENT" or "3":
    CODE = "STUDENT"
    PORTABLENESS()

1 Answers1

2

Change:

if foo == "ADMIN" or "1":

to

if foo == "ADMIN" or foo == "1":

and so on..

The issue is,

if foo == "ADMIN" or "1":

is evaluated as

if (foo == "ADMIN") or "1":

where or "1" will always evaluate to True. Hence the issue.

Another alternative would be:

if foo in ("ADMIN", "1"):
karthikr
  • 97,368
  • 26
  • 197
  • 188