输入: 西瓜重量(单位:斤):25 顾客付款(单位:元):20

输出: 应付货款:21.25 元 应找钱数:-1.25 元

输入: 西瓜重量(单位:斤):7 顾客付款(单位:元):8.5

输出: 应付货款:7.00 元 应找钱数:1.50 元

代码如下:

weight = float(input("西瓜重量(单位:斤):")) payment = float(input("顾客付款(单位:元):"))

if weight > 20: price = 0.85 elif weight > 15: price = 0.90 elif weight > 10: price = 0.95 elif weight > 5: price = 1.00 else: price = 1.05

total_cost = round(price * weight, 2) change = round(payment - total_cost, 2)

print("应付货款:{} 元".format(total_cost)) print("应找钱数:{} 元".format(change))


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

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