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])
Python中简单的def及return返回值
于 2024-10-23 12:30:27 首次发布