尝试将列表项(PreCalc)传递到一个简单的函数中。试图将列表转换为元组版本(calc),然后调用该函数。
获取错误消息:TypeError:' tuple'对象不可调用
如何将输入()传递给函数?
def calc(x,y,z):
a = x * (1 + (y/100))
b = a * (1 - (z/100))
c = (b / 12)
d = x * (1 - (z/100)) / 12
print("the annual gross salary is %.2f" %(x),"kEUR")
print("the annual bonus opportunity is %.2f" %(y), "%")
print("the annual gross salary plus bonus is %.2f" %(a), "kEUR")
print("you have to pay around %.2f" %(z),"% in tax")
print("the annual net salary incl. bonus is %.2f" %(b),"kEUR")
print("The average monthly post-tax salary incl. bonus is %.2f" %(c),"kEUR")
print("The average monthly post-tax salary excl. bonus is %.2f" %(d),"kEUR")
PreCalc = [0,0,0]
PreCalc[0] = int(input("please enter your annual gross salary"))
PreCalc[1] = int(input("please enter your bonus opportunity in %"))
PreCalc[2] = int(input("please enter your tax rate in %"))
print(PreCalc)
calc = tuple(PreCalc)
print(calc)
calc()
答案 0 :(得分:0)
您无需将列表转换为元组
calc(*PreCalc)
并且评论说不要影响calc函数。
您也不需要使用列表,而是可以这样做。
x = int(input("please enter your annual gross salary"))
y = int(input("please enter your bonus opportunity in %"))
z = int(input("please enter your tax rate in %"))
calc(x, y, z)