0

I've not long started with python and I've looked over a lot of posts on here but just cant seem to work out whats wrong with my code... If the user types in N or n then surely my elif would kick in but it still plays the sound and prints out "sound played". Can anyone help please? Thank you.

test2 = raw_input("Would you like to test the sound? Y\N or exit? ")
if test2 == "Y" or "y":
    winsound.PlaySound('C:/Windows/Media/tada.wav', winsound.SND_FILENAME)
    print ("Sound Played")
elif test2 == "N" or "n":
    print ("Test skipped")
elif test2 == "exit":
    print ("Test exit")
else:
    print ("Please choose an option")
Joelcb
  • 3
  • 1
  • 3
    Possible duplicate of [How do I test one variable against multiple values?](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values) – Łukasz Rogalski Aug 30 '16 at 20:02
  • Wow, it's like an ultimate duplicate, but 4 answers (and none with _actual_ explanation **why** is this happening) had to be posted. Nice... – Łukasz Rogalski Aug 30 '16 at 20:07

2 Answers2

2
if test2 == "Y" or "y"

should be

if test2 == "Y" or test2 == "y"

Python is evaluating "y" as true

jongusmoe
  • 36
  • 1
0

You wrote:

elif test2 == "N" or "n":

and you mean:

elif test2 == "N" or test2 == "n":
chenchuk
  • 5,324
  • 4
  • 34
  • 41