gpt4 book ai didi

python - PYTHON语法错误吗?

转载 作者:行者123 更新时间:2023-12-03 08:15:29 25 4
gpt4 key购买 nike

当我尝试运行该程序时,我不断收到“无效语法”消息。在“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请注意,我还必须稍微改变一下您的值,以了解您正在执行的运算符链接...

关于python - PYTHON语法错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22924535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com