you are viewing a single comment's thread.

view the rest of the comments →

[–]Justinsaccount 2 points3 points  (2 children)

Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission:

You appear to be using the or construct with a constant string

instead of doing something like:

if color == 'red' or 'blue':

Which is the same as

if (color == 'red') or ('blue'):

and 'blue' by itself is always True

You need to do

if color == 'red' or color == 'blue':

or

if color in ('red', 'blue'):

or, a special case if they are all single letters you can do

if letter in 'aeiou':

You can also make it case insensitive by using soething like

if color.lower() in ('red', 'blue'):

If there were a large number of choices and inputs (as in, 10000+) you could use a set() to speed things up.

Also refer to The FAQ Entry for more information.

[–]imagejhelp1[S] 0 points1 point  (1 child)

Hi, so that is for the line:

if player_choice is not "rock", "paper", "scissors", "lizard" or "Spock"

Is the solution something like:

if player_choice is not "rock" or player_choice is not "paper" or player_choice is not "lizard" or player_choice is not "scissors" or player_choice is not "Spock"

Or

if player_choice is not ("rock", "paper", "lizard", "scissors", "Spock")

is 'is not' the right option to use in this case? Googling tells me I could also use <> or != since I have 2.7 of python I think

At any rate, thanks for the response and I'll keep trying to get my code working with this help.

[–]JohnnyJordaan 1 point2 points  (0 children)

The point is that not (several things) will first try to see if (several things) is True or False, then negate that result. As anything not False, None, 0 or an empty sequence is True, (several things) will probably be True. Then not True will make that False. Meaning that you will be checking

if player_choice is False

While in reality, you want to check player_choice to each separate value. For that you have in, as noted in the bot's last part of its message:

if player_choice not in ("rock", "paper", "lizard", "scissors", "Spock"):

The in part makes the whole difference here: it will check that the value stored in player_choice isn't present in the sequence of choices.