编程论坛
注册
登录
编程论坛
→
Python论坛
求救大佬
srl237381
发布于 2018-12-27 20:09, 1658 次点击
如果一个人至少30岁, 并且成为美国公民至少9年,就有资格成为美国参议员。作为美国众议员,年限分别是25岁和7年。编写个程序, 接受个人的年龄和公民年数作为输入,并输出他的参议院和众议院资格。
1 回复
#2
FishK
2019-01-04 10:16
程序代码:
"""
I: 年龄age,成为美国公民的时间times
P: 1. age>=30 and times>=9
2. age>=25 and times>=7
O: 是否有资格成为美国参议员或众议员
"""
def
get_input():
while
True:
try
:
age = int(input(
"
请输入年龄:
"
))
times = int(input(
"
请输入成为美国公民的时间:
"
))
break
except
ValueError:
pass
return
age, times
def
process(age, times):
if
age >= 30
and
times >= 9:
output(
"
具备参议员资格和众议员资格
"
)
elif
age >= 25
and
times >= 7:
output(
"
具备众议员资格
"
)
else
:
output(
"
不具备任何资格
"
)
def
output(s):
print
(s)
if
__name__
==
'
__main__
'
:
age, times = get_input()
process(age, times)
1