Why doesn't this code work?

if question3.lower == "moral" or "ethical" or "religious" or "political":
  print("Good job ")
  score=+1
else:
  print("That was incorrect. Did you actually pay attention to what you read? ")
  print("The answers that would have been accepted is either, moral, ethical, Religious or Political ")
question4=input("    How many COs were there? ")
if question4=="16,000" or "16000":
  print("Good job ")
  print(" ")
  score=+1
else:
  print("That was incorrect. Read more carefully from now on ")
  print(" ")**

P.S the question part says it right no matter what
How do I fix this?

1 Like

You need to change this line

if question3.lower == “moral” or “ethical” or “religious” or “political”:

To

if question3.lower() == “moral” or question3.lower() == “ethical” or question3.lower ()== “religious” or question3.lower() == “political”:

And change this line

if question4==“16,000” or “16000”:

To

if question4 == “16,000” or question4 == “16000”:
3 Likes

you also need to have () after .lower to call the function. You could do this:

if question3.lower() in {"moral", "ethical", "religious", "political"}:
4 Likes

As the users above have said, this line is wrong. It comes out to the python side looking like this:

(question3.lower == "moral") or bool("ethical") or bool("religious") or bool("political")
# Since the strings are not empty, bool will always return true, so in the end, it will always be true

As @UMARismyname said, I recommend using “in” instead.

2 Likes

This is the most Pythonical way.

3 Likes

This very term reminds me of a guy on Discord, he had a massive ego and would always criticize Python beginners and say stuff like “Your code’s not pythonic” or something along those lines and thought he was genuinely cool.

I honestly care little for the Pythonical way, but it is sometimes better and often just looks cooler.

Bro found my alt man.

Welcome to relpit ask @user20110918. Hope you enjoy your time with us.