0

I can't get my head around this particular if..else statement:

print("Do you want to run the next bit of code? Y/N")
n = input()

if n == "Y" or "y":
    j = [12, 43, 54, 65]
    for i in j:
        print (i, end="" "\t")

elif n == "N" or "n":
    print("You get numbers if you had pressed Y")

else:
    print("That's not an option")

My problem here is, whatever the value I give for n, it always gives me the output of Y or y. I always get the output as the array numbers. Which means that my condition is not working. So what is actually the problem with the first condition?

Ewan
  • 13,854
  • 6
  • 47
  • 58
zuestech
  • 93
  • 1
  • 6

1 Answers1

0

Check this. The following code works.

print("Do you want to run the next bit of code? Y/N")
n = input()
if n in ["Y", "y"]:
    j = [12, 43, 54, 65]
    for i in j:
        print (i, end="" "\t")
elif n in ["N", "n"]:
    print("You get numbers if you had pressed Y")
else:
    print("That's not an option")
Neeraj Hanumante
  • 1,363
  • 1
  • 16
  • 31