下面是一个简单的游泳消费系统的python代码示例:

def calculate_price(age, time):
    # 根据年龄和时间计算价格
    price = 0
    
    if age < 18:
        price = 5
    elif age >= 18 and age < 60:
        if time < 2:
            price = 10
        else:
            price = 15
    else:
        price = 5
    
    return price

def main():
    age = int(input("请输入您的年龄:"))
    time = float(input("请输入您的游泳时间(小时):"))
    
    price = calculate_price(age, time)
    print("您需要支付的价格为:{}元".format(price))

if __name__ == '__main__':
    main()

在这个示例中,我们定义了一个calculate_price函数,根据输入的年龄和游泳时间计算价格。然后在main函数中,我们接收用户的输入,并调用calculate_price函数计算价格,最后输出结果。

Python 游泳消费系统代码示例

原文地址: https://www.cveoy.top/t/topic/qqKU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录