gpt4 book ai didi

python - 从python中的另一个函数调用变量

转载 作者:行者123 更新时间:2023-11-28 21:49:38 24 4
gpt4 key购买 nike

我已经定义了这两个函数,我需要从第一个函数调用函数 2 中的 income 和 allowance,基本上我想计算函数 2 中的 finalIncome(该行代码已注释)。继承人的代码:

def personalAllowance():
income = int(input("Enter your annual salary: £"))
allowance = 10600
if(income>100000):
for i in range (100000, income):
if(income%2==0):
allowence = allowence - 0.5
if(allowence<0):
allowence = 0
print("Personal Allowance = " + str(allowence))
else:
print("Personal Allowance = " + str(allowence))
return (income , allowance)


def incomeTax():
print("\n")
#finalIncome = income - allowence
print(finalIncome)
taxBill = 0
if(finalIncome <= 31785):
taxBill = finalIncome * (20/100)
elif(finalIncome > 31785 and finalIncome < 150000):
taxBill = finalIncome * (40/100)
elif(finalIncome >= 150000):
taxBill = finalIncome * (45/100)
print (taxBill)


incomeTax()

最佳答案

保存对这些值的引用,然后减去它们:

income, allowance = personalAllowance()
finalIncome = income - allowance

关于python - 从python中的另一个函数调用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33193220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com