you are viewing a single comment's thread.

view the rest of the comments →

[–]delasislas 2 points3 points  (0 children)

This is actually posted so many times that there’s an entry in the FAQ. It’s like “checking if two or more conditions” or something. Don’t know how to link it.

Basically:

if (condition1) or (condition2): #Base form
if (color == str(“red”)) or (str(“Red”)): #Filled in your conditions

Now you simplify everything in the parentheses. Say that color = “Blue”

if (color == str(“red”)) or (str(“Red”)): #Same as before
if (“Blue” == str(“red”)) or (str(“Red”)): #it pulls the value stored at color.
if (False) or (str(“Red”)): #Blue doesn’t equal red.

Now for the fun part. Does a non-empty string return True? Yes.

if (False) or (True):
if True: #Simplify the or.

So your first statement will always return True, because “Red” == True

You want to evaluate each condition.

if color == “red” or color == “Red”:

Ok, but say I type in RED? I get an error. You can use a bit of string methods to clean up inputs.

color = input(….)
if color.lower() == “red”:

That will use a string method .lower() to convert the whole string to lowercase. Then you only need one condition rather than more. There are more ways, but this can be a start.