当我尝试运行该程序时,我不断收到“无效语法”消息。在“else”语句之后,它以红色突出显示“age”。我不确定自己做错了什么。

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.')

最佳答案

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

是语法错误。 :语句之后,除了else之外,您不能再有其他任何内容。

也许您想要一个elif子句1?
elif 30 > age >= 25 and 9 > citizen >= 7:
    ...

1请注意,我还必须稍微改变一下您的值,以了解您正在执行的运算符链接...

10-08 12:42