[英]How do I use a python table?
I was requested by my teacher to write a program in python which would require visitors of said attraction to insert the number of family members they are visiting with, and based off of that, have them know the admission fee.我的老师要求我用 python 编写一个程序,该程序将要求所述景点的游客插入他们正在拜访的家庭成员的数量,并据此让他们知道入场费。 The admission fees given were $25 for anybody under 16, and 40 for anybody over 40. This is what I've got so far:
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()
How would I go about grabbing said admission values and adding them all together?我将如何获取所说的入场价值并将它们加在一起? Thank you!
谢谢!
members = {}
members = {}
exit()
in this case).exit()
)。pass
you may call your program again using main()
or exit using exit()
).pass
你可以使用main()
再次调用你的程序或使用exit()
)。 Here is the working code:这是工作代码:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.