Oscar Cheung
Oscar Cheung

Reputation: 1

Variable syntax error (Python)

I'm new to coding with python and I've came across an issue with my variables in an "if" or "else" command.

Answer = input("Yo stupid, What\'s nine plus ten?")
if Answer == 19: print("Your smarter then me.")
else Answer >= 21: print("You stupid!")

^^ When I attempt to run my code It tells me I have made an error with my syntax. It always pops up with my variable "Answer" in the "if" or "else" command. Any help would be greatly appreciated. Thanks in advance.

Upvotes: 0

Views: 85

Answers (2)

Tiphaine
Tiphaine

Reputation: 131

else: does not take a condition afterwards. In your case use elif <condition>:.

Upvotes: 0

TerryA
TerryA

Reputation: 59974

elif (short for "else if") should be used if you want to test another condition for Answer. else is used on its on for every other option that Answer could be that doesn't fit the previous conditionals.

Upvotes: 4

Related Questions