有些人可以用我的python代码帮助我,它给我一个错误,说明不支持的操作数类型 - :
Numberone = 564
numbertwo = 270
def tax(tax):
tax = ("20%")
def subtract(subtract):
subtract = Numberone - numbertwo
total = subtract - "20%"
答案 0 :(得分:1)
您的第一个问题是您无法从函数中减去字符串。
然后你有很多相同的名字 - 不要这样做。函数应该像行为一样命名。像这样:
def compute_tax(amount):
tax_rate = 0.20 # 20 percent
return amount * tax_rate
然后,如果你想使用它,你可以通过将()
附加到函数名称并给它参数来调用函数:
# Not terribly descriptive names, but you didn't
# give me anything else to go by.
number_one = 564
number_two = 270
total = number_one - number_two
tax_amount = compute_tax(total)
print(total - tax_amount)