我的老师要求我在python中编写一个程序,要求所有景点的访问者插入他们正在访问的家庭成员的数量,并根据这一点,让他们知道入场费。 16岁以下的人入场费为25美元,40岁以上的人入场费为40美元。 这是我到目前为止所得到的:
def main():
admission = 0
print("Welcome to Wally World - use this program to calculate your admission fees")
number = int(input("How many members will you be taking with you? "))
members = {}
for n in range(0,number):
age = int(input("Please enter your ages: "))
if age <= 16:
admission = 25
if age > 16:
admission = 40
main()
我如何抓住所述录取值并将它们全部加在一起? 谢谢!
答案 0 :(得分:1)
members = {}
exit()
)。pass
您可以使用main()
再次致电您的计划,或使用exit()
退出。以下是工作代码:
def main():
admission = 0
print("Welcome to Wally World - use this program to calculate your admission fees")
number = int(input("How many members will you be taking with you? "))
if number < 0: exit()
for n in range(0,number):
age = int(input("Please enter your ages: "))
admission += (25 if age <= 16 and age > -1 else 40 if age> 16 else 0)
return admission
main()