简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM