tags:

views:

49

answers:

2

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 "yes" or"yep" or"yeah":
    message("Playing Video")
    subprocess.Popen(playvid)
else:
    pass
+1  A: 

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"] :
ghostdog74
probably Alquimista also can do liker.lower() in ["Y","y","yes","yep","yeah"] ::-)
Tumbleweed
@shahjapan: if you're using lower() then why include `"Y"` on the list?
nosklo
+1  A: 

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"...
avpx
Small correction: `==` binds tighter than `or`, so the OP is testing the truth of `(r=="Y") or "y" or "yes"` etc.
balpha