Python中简单的def及return返回值

def abc(c):
    new = sum(c)
    new1 = new
    if new <=300 :              #输入价格若小于300的话是原价
        new1 = new
    elif 300 < new <= 500:      #在300~500(包含两端)以9折
        new1 = round(new * 0.9,2)
    elif 500 < new <=1000:       #在500~1000(包含两端)以8折
        new1 = round(new * 0.8,2)
    elif 1000 < new <= 2000:       #在1000~2000(包含两端)以7折
        new1 = round(new * 0.7,2)
    return new,new1                #返回多个值为<class 'tuple'>,返回一个为<class 'int'>
print("开始结算")
ist = []                #创建空列表
while True:
    price = float(input("价格为多少: "))
    if price == 0:
        break          #如果price为0则退出循环
    else:
        ist.append(price)    #如果不为0则添加到列表
yuan = abc(ist)             #yuan的类型为<class 'tuple'>
print("合计金额:" ,yuan[0], "打折完以后金额:",yuan[1])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值