Python 2.7 Python-If、elif语句
我开始使用python的时间不长,我在这里查阅了很多帖子,但似乎无法找出我的代码出了什么问题。。。 如果用户输入N或N,那么我的elif肯定会启动,但它仍然播放声音并打印出“播放的声音”。 有人能帮忙吗?多谢各位Python 2.7 Python-If、elif语句,python-2.7,loops,if-statement,Python 2.7,Loops,If Statement,我开始使用python的时间不长,我在这里查阅了很多帖子,但似乎无法找出我的代码出了什么问题。。。 如果用户输入N或N,那么我的elif肯定会启动,但它仍然播放声音并打印出“播放的声音”。 有人能帮忙吗?多谢各位 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'
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")
应该是
if test2 == "Y" or test2 == "y"
Python将“y”评估为true
应该是
if test2 == "Y" or test2 == "y"
Python将“y”评估为真您写道:
elif test2 == "N" or "n":
你的意思是:
elif test2 == "N" or test2 == "n":
你写道:
elif test2 == "N" or "n":
你的意思是:
elif test2 == "N" or test2 == "n":
《魔兽世界》的可能复制品,就像一个终极复制品,但必须发布4个答案(没有一个能解释为什么会发生这种情况)。很好…可能是《魔兽世界》的翻版,它就像一个终极翻版,但必须发布4个答案(没有一个能解释为什么会发生这种情况)。美好的