I am trying to create a simply US Income Tax calculator in python using functions. No matter what I put as filing status I always get the numbers for "single". I am trying to have it run the correct function based on what is input as the filing status by the user.
I have have created functions for each filing status to get tax rate as well as to get the flat tax minimum as outlined by the tax code.
I know that the end result isn't going to be exactly correct but I am doing this as an exercise in functions and creating a more complex program
Any help is appreciated.
income = float(input("How much do you make? :"))
filing_status = input("What is your filing status? :").capitalize()
# Determine Static Deduction
def single_static_calc():
if income <= 10275:
return 0
elif income <= 41775:
return 1027.59
elif income <= 89075:
return 4807.50
elif income <= 170050:
return 15213.50
elif income <= 215950:
return 34647.50
elif income <= 539900:
return 49335.50
else:
return 162718
def ms_static_calc():
if income <= 10275:
return 0
elif income <= 41775:
return 1027.59
elif income <= 89075:
return 4807.50
elif income <= 170050:
return 15213.50
elif income <= 215950:
return 34647.50
elif income <= 323925:
return 49335.50
else:
return 86127
def hh_static_calc():
if income <= 14650:
return 0
elif income <= 55900:
return 1465
elif income <= 89050:
return 6415
elif income <= 170050:
return 13708
elif income <= 215950:
return 33148.50
elif income <= 539900:
return 47836.50
else:
return 162218.50
def mj_static_calc():
if income <= 20550:
return 0
elif income <= 83550:
return 2055
elif income <= 178150:
return 9615
elif income <= 340100:
return 30427
elif income <= 431900:
return 69295
elif income <= 647850:
return 98671
else:
return 174253.50
def static_criteria():
if filing_status == "Single":
return single_static_calc()
elif filing_status == "Married Separate":
return ms_static_calc()
elif filing_status == "Head of Household":
return hh_static_calc()
elif filing_status == "Married Jointly":
return mj_static_calc()
else:
return single_static_calc()
static = static_criteria()
print("Static Amount is:", static)
# Determine your tax rate
def single_rate_calc():
if income <= 10275:
return .10
elif income <= 41775:
return .12
elif income <= 89075:
return .22
elif income <= 170050:
return .24
elif income <= 215950:
return .32
elif income <= 539900:
return .35
else:
return .37
def ms_rate_calc():
if income <= 10275:
return .10
elif income <= 41775:
return .12
elif income <= 89075:
return .22
elif income <= 170050:
return .24
elif income <= 215950:
return .32
elif income <= 323925:
return .35
else:
return .37
def hh_rate_calc():
if income <= 14650:
return .10
elif income <= 55900:
return .12
elif income <= 89050:
return .22
elif income <= 170050:
return .24
elif income <= 215950:
return .32
elif income <= 539900:
return .35
else:
return .37
def mj_rate_calc():
if income <= 20550:
return .10
elif income <= 83550:
return .12
elif income <= 178150:
return .22
elif income <= 340100:
return .24
elif income <= 431900:
return .32
elif income <= 647850:
return .35
else:
return .37
def rate_criteria():
if filing_status == "Single":
return single_rate_calc()
elif filing_status == "Married Separate":
return ms_rate_calc()
elif filing_status == "Head of Household":
return hh_rate_calc()
elif filing_status == "Married Jointly":
return mj_rate_calc()
else:
return single_rate_calc()
rate = rate_criteria()
print("rate is:", rate)
#Taxes
after_static = income - static
rate_tax = after_static * rate
tax_owed = rate_tax + static
income_after_tax = income - tax_owed
print("With the income of $", income, "you will pay $",tax_owed,"in tax.")
print("You will have $",income_after_tax,"Left")
capitalize()
only capitalizes the first letter of the string, So filling_status == Single
is working and the else
block is working, both of which are returning single_statuc_calc()
Python String capitalize() function is used to convert only the first character to the uppercase letter, rest all characters are lowercase. refer
change
filing_status = input("What is your filing status? :").capitalize()
to
filing_status = input("What is your filing status? :").lower()
also, change
Single -> single
Married -> married
Head of Household -> head of household
Married Jointly -> married jointly
Change 1
income = float(input("How much do you make? :"))
filing_status = input("What is your filing status? :").lower()
Change 2
def static_criteria():
if filing_status == "single":
return single_static_calc()
elif filing_status == "married separate":
return ms_static_calc()
elif filing_status == "head of household":
return hh_static_calc()
elif filing_status == "married jointly":
return mj_static_calc()
else:
return single_static_calc()
Change 3
def rate_criteria():
if filing_status == "single":
return single_rate_calc()
elif filing_status == "married separate":
return ms_rate_calc()
elif filing_status == "head of household":
return hh_rate_calc()
elif filing_status == "married jointly":
return mj_rate_calc()
else:
return single_rate_calc()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.