商品单价99.80元,优惠价91.80元,返现150.00元,运费15.00元,输入购买商品数量,计算并输出购买商品的总金额、运费、返现金额、折扣率、商品优惠金额、实付总额。Python
时间: 2024-09-11 18:15:54 浏览: 92
在Python中,你可以创建一个函数来计算这个购物车的总金额。这里是一个简单的示例:
```python
def calculate_total(item_count, unit_price, discount_price, refund, shipping):
# 计算商品原价总金额
total_price = item_count * unit_price
# 计算商品优惠金额
savings = item_count * (unit_price - discount_price)
# 计算实际支付的金额
after_discount = total_price - savings
# 折扣率(假设是基于原价)
discount_rate = (total_price - after_discount) / total_price if total_price != 0 else 0
# 实付总额
net_amount = after_discount + shipping - refund
return {
'总金额': total_price,
'运费': shipping,
'返现金额': refund,
'折扣率': discount_rate,
'商品优惠金额': savings,
'实付总额': net_amount
}
# 示例输入
item_count = int(input("请输入购买的商品数量:"))
unit_price = 99.80
discount_price = 91.80
refund = 150.00
shipping = 15.00
result = calculate_total(item_count, unit_price, discount_price, refund, shipping)
for key, value in result.items():
print(f"{key}: {value}")
阅读全文