当我尝试运行此程序时,我不断收到“无效语法”消息。在“其他”声明之后,它突出显示红色的“年龄”。我不确定我做错了什么。
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.')
答案 0 :(得分:4)
else age < 30 >= 25 and citizen < 9 >= 7:
是语法错误。在:
声明之后,您不能拥有else
以外的任何内容。
也许你想要一个elif
条款 1 ?
elif 30 > age >= 25 and 9 > citizen >= 7:
...
1 请注意,我还需要稍微切换一下你的值来理解你正在做的操作符链接......
答案 1 :(得分:0)
else
中的else age < 30 >= 25 and citizen < 9 >= 7:
应更改为elif
。