0

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.

2
  • 2
    Use elif instead of else Commented Oct 20, 2016 at 0:55
  • 1
    Additionally, input returns a string, so "19" == 19 will be false. Commented Oct 20, 2016 at 0:58

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Should also mention that the conditionals are resulting in a TypeError, it should be if Answer == '19', elif Answer >= '21' , but hit the nail on the head with the first one :-)
Thanks for helping, however, I tried what you said (to the best my pea-brain can comprehend), but now it says I have an error with "print" Sorry if i'm a bit of a nuisance here. Answer = input("Yo stupid, What\'s nine plus ten?") if Answer == '19' print("Your smarter then me.") elif Answer >= '21' print("You stupid!")
Don't forget to use the colons at the end of each if/elif
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.