欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

第一次写博客之python小作业

程序员文章站 2024-03-18 14:54:22
...

第一次写博客之python小作业

有家电影院根据观众的年龄收取不同的票价:不到三岁的观众免费;3-12岁的观众为10美元;超过12岁的观众为15美元。请编写一个循环,在其中询问用户的年龄,并指出其票价。并且使用break语句在用户输入’quit’时退出循环。

account = True
while account:
    age = input("请输入观众的年龄(输入’quit’时退出循环):")
    if age == "quit":
        break
    elif int(age) < 3:
        price = 0
        print("该用户应付价格是%d美元" %price)
        continue
    elif 3 <= int(age) < 12:
        price = 10
        print("该用户应付价格是%d美元" %price)
        continue
    else:
        price = 15
        print("该用户应付价格是%d美元" %price)
        continue

第一次写博客之python小作业