首页 > 解决方案 > Python:计算不同输入价格的增值税金额

问题描述

嘿,我在计算不同价格的增值税时遇到了麻烦。如果 priceR250 则增值税率=7.5%。当我运行我的代码时,我没有收到增值税金额。

item_price1 = int(input("Enter the item price: R "))

def vat_calc(price):
    if price<100:
        vat_amount=price*0.15
    elif price>101 and price<249:
        vat_amount=price*0.10
    else:
        vat_amount=price*0.075
print("VAT amount: R", vat_calc(item_price1))

标签: python

解决方案


你永远不会返回任何东西,return在你的函数末尾添加一条语句:

item_price1 = int(input("Enter the item price: R "))

def vat_calc(price):
    if price<100:
        vat_amount=price*0.15
    elif price>101 and price<249:
        vat_amount=price*0.10
    else:
        vat_amount=price*0.075
    return vat_amount

print("VAT amount: R", vat_calc(item_price1))

推荐阅读