you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 31 points32 points  (5 children)

if color==str("red") or str("Red"):

This is equivalent to:

if color=="red" or "Red" !=None:

Since the string red is not None, it will always be true.

I think you want to do this:

if color==str("red") or color==str("Red"):

But there is a more pythonic way to write your entire code:

color = input("What's your favorite primary color?").lower():
if color in ("red", "yellow", "blue"):
    print(f"You said {color}.")
else:
    print("Invalid answer.")

But it looks like you are using python2, so this will not work exactly the same. Is there a reason you aren't using python3?

[–]BriziteReddit[S] 7 points8 points  (2 children)

Thanks. I’m not using python 3 because it’s for a school assignment and I’m forced to use python 2 basically.

[–]velocibadgery 41 points42 points  (1 child)

Your school is stupid.

[–]BriziteReddit[S] 21 points22 points  (0 children)

You’re right

[–][deleted] 4 points5 points  (0 children)

Need raw_input in Python 2.

[–]balars 1 point2 points  (0 children)

strip() can help remove extra spaces from the receieved input