小明想要购买一款游戏,价格为10美元。他希望通过编写一个简单的程序来计算他需要支付的总金额,包括税费和折扣。假设税费为5%,折扣为2美元。请帮助小明编写一个Python程序来计算他需要支付的总金额。

python
def calculate_total_amount(item_price, tax_rate, discount):
tax = item_price * tax_rate
total_amount = item_price + tax - discount
return total_amount
item_price = 10
tax_rate = 0.05
discount = 2
total_amount = calculate_total_amount(item_price, tax_rate, discount)
print("总金额为:", total_amount)
运行上述程序,输出结果为:
总金额为: 9.5
因此,小明需要支付的总金额为9.5美元。

查看详情

查看详情