0

I keep getting an "invalid syntax" message when I try to run this program. It highlights "age" in red after the "else" statement. I'm not sure what I did wrong.

age = float(input('How old are you? '))
citizen = float(input('How long have you been an American citizen? '))
if age >= 30 and citizen >= 9:
    print('You are eligible to become a US Senator and a House Representative!')
else age < 30 >= 25 and citizen < 9 >= 7:
    print('You are only eligible to become a House Representative.')
if age < 25 or citizen < 7:
    print('You are not eligible to become a US Senator or a House Represenatative.')
4
  • What's the full traceback of the syntax error? It should have a line number, preview of the line, character position, etc. edit your question to include that information Commented Apr 7, 2014 at 22:49
  • 2
    else ... is not valid. You mean elif ... Commented Apr 7, 2014 at 22:51
  • 1
    age < 30 >= 25 is weird, too (it does not do what you want it to do in this case) Commented Apr 7, 2014 at 22:55
  • Yes, The program is running, but it is not working the way it is suppose to. I'm not sure how to only activate that line if the value is under 30 but greater or equal to 25. Commented Apr 7, 2014 at 23:01

2 Answers 2

4
else age < 30 >= 25 and citizen < 9 >= 7:

is a syntax error. You can't have anything other than a : after an else statement.

Maybe you wanted an elif clause1?

elif 30 > age >= 25 and 9 > citizen >= 7:
    ...

1Note that I also had to switch around your values a bit to make sense of the operator chaining that you were doing ...

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

2 Comments

s/else/elif/ would also be helpful in the answer so the OP knows how to fix.
@SethMMorton -- Yeah, that's not all that's wrong though. OP also has a bit of problems with their operator chaining. I was fixing it :)
0

The else in else age < 30 >= 25 and citizen < 9 >= 7: should be changed to elif.

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.