开发者

Popen always run, ignoring the if

开发者 https://www.devze.com 2022-12-15 23:35 出处:网络
I want that when I respond other thing diferent that yes, the subprocess don\'t run. r = raw_input(\'\\nDo you want play the video?\\n\\nY:YesN:No\\n\\n\')

I want that when I respond other thing diferent that yes, the subprocess don't run.

r = raw_input('\nDo you want play the video?\n\nY:Yes  N:No\n\n')
if r == "Y" or "y" or "y开发者_如何学运维es" or"yep" or"yeah":
    message("Playing Video")
    subprocess.Popen(playvid)
else:
    pass


change this

if r == "Y" or "y" or "yes" or"yep" or"yeah":

to

if r in ["Y","y","yes","yep","yeah"] :

or change your response to lower case

r = raw_input('\nDo you want play the video?\n\nY:Yes  N:No\n\n').lower()
if r in ["y","yes","yep","yeah"] :


I'm not sure if I fully understand your question, but I believe the issue is your syntax in this line:

if r == "Y" or "y" or "yes" or"yep" or"yeah":

You are testing the truth of "Y", "y", etc, which all evaluate to "true". Put all of the values in a sequence and do:

if r in seq:

That should be a much cleaner way to do it than

if r == "Y" or r == "y"...
0

精彩评论

暂无评论...
验证码 换一张
取 消