提交时间:2024-12-24 15:09:40
运行 ID: 50539
def calculate_discount(total_amount): if total_amount < 2000: discount = 0 elif 2000 <= total_amount < 3000: discount = 0.20 # 8折优惠,即20%的折扣 elif 3000 <= total_amount < 4000: discount = 0.30 # 7折优惠,即30%的折扣 else: discount = 0.40 # 6折优惠,即40%的折扣 return total_amount * (1 - discount) # 测试程序 total_amount = float(input("请输入您的购物总金额:")) discounted_price = calculate_discount(total_amount) print(f"{discounted_price:.1f}")