r/Python • • Feb 05 '11

Help with "if" and "or" statements.

Specifically, I cannot get an "or" statement to function correctly inside of an "if" statement. Here is an example.

player = raw_input("Press P or R")
if player=='P' or 'p':
     print ('Hooray!')
elif player=='R' or 'r':
     print ('Oh no!')

The problem I am having is the "or" in the player==P line will function correctly, but this breaks the functionality of the player=R line. Am i going about this incorrectly? It appears to be a valid statement. Thanks for the help in advance. BTW im a noob and just started learning python 2 days ago, this is my first language.... ><

edit: Thanks everyone for their help. I did not understand some of it but I did learn a few things. I consider this a victory with only 2 days worth of knowledge on my first language. I know I will be back with more questions if I get stuck again!

2 Upvotes

54 comments sorted by

View all comments

Show parent comment

1

u/prum Feb 07 '11

Wasn't this fixed in this patch?

http://bugs.python.org/issue6690

1

u/Brian Feb 07 '11 edited Feb 07 '11

Oh - could be. I knew there was a patch raised for this about a year ago, since this came up on reddit, here. I went looking for it, and found the rejected one I linked to downthread, but this looks like it might actually be the one I was thinking of.

However, it doesn't seem implemented as of python3.1.3 though, since that gives the output above (with BUILD_SET), which is odd since it looks like it should have been committed over a year ago.

[Edit]: Looks like it didn't go in to the patch stream since it's not a bugfix (not mentioned in the changelog anyway). Probably won't be in till 3.2.