2

I have defined these two functions and I need to call income and allowance in function 2 from the first function, basically I want to calculate the finalIncome in function 2 (that line of code is commented). Heres the code:

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()
asked Oct 18, 2015 at 0:55

3 Answers 3

2

Save references to those values and then subtract them:

income, allowance = personalAllowance()
finalIncome = income - allowance
answered Oct 18, 2015 at 0:58
Sign up to request clarification or add additional context in comments.

Comments

2

You just have to call personalAllowance and assign the return value to something.

For example:

income, allowance = personalAllowance()
answered Oct 18, 2015 at 0:58

Comments

1

Since you don't actually need the "income" or "allowance", instead of returning a tuple, just return the difference as shown where I have commetned

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 ## Just return the difference
def incomeTax():
 print("\n")
 finalIncome = personalAllowance() ## This will return difference
 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()
answered Oct 18, 2015 at 1:03

1 Comment

Thing is I'll have to do other calculations as well in other functions, but for this, it works fine. Thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.