0

I wrote the below code. Whenever I enter a non-accepted value such as a, b, c, or d, I want the else statement not-nested to be run, but every-time I do, it just runs the Instagram input. I was wondering how I can go about fixing this issue. Thank you.

if commandPrompt.lower() == 'a' or 'b' or 'c' or 'd':
    instagram = input("Will you share this on Instagram? (y/n): ")
    if instagram.lower() == 'y':
        print()
        print("Thanks! You will get 5 knuts off your purchase!")
    else:
        print("Ok. No problem.")
else:
    print("You have entered an invalid selection. Please try again.")

1 Answers1

1

Your condition is evaluated like so:

if (commandPrompt.lower() == 'a') or 'b' or 'c' or 'd':

which is always True. Try something like this instead:

if commandPrompt.lower() in ['a', 'b', 'c', 'd']:
Cornholio
  • 454
  • 2
  • 8