-3

I did very simple code, I literally just started python but I created some IF and elif statements and it always, prints the first If statement, sorry for bothering people with this petty problem. I tried to search and couldn't find my problem due my lack of experience.

    name = input ("what is your name")
if name == ("x") or ("y"):
    print ("Hello")
elif name == "n" or name == "m" or name ==  "N" or name == "M":
    print  ("a")
else:
    print ("b")
juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
Novicus
  • 1
  • 1

2 Answers2

0
 if name == "x" or name == "y"

works

098799
  • 462
  • 1
  • 4
  • 17
0

your first statement is equivalent to

if (name == 'x') or ('y')

NOT

if (name == 'x') or (name == 'y')

and

if 'y' 

is always true

so your code shortcuts and uses the first condition

markers
  • 152
  • 6