PYTHON Invalid Syntax Error?
当我试图运行这个程序时,我一直收到一条"无效语法"消息。它在"else"语句后以红色突出显示"age"。我不知道我做错了什么。
1 2 3 4 5 6 7 8 | 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.') |
1 | else age < 30 >= 25 and citizen < 9 >= 7: |
是语法错误。在
也许你想要一个
1 2 | elif 30 > age >= 25 and 9 > citizen >= 7: ... |
1请注意,我还必须稍微转换一下您的值,以便理解您正在进行的运算符链接…