Created
September 1, 2012 10:37
-
-
Save danielpclark/3569222 to your computer and use it in GitHub Desktop.
Figure out Virginia state and Federal tax based on income.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Federal and Virginia State Tax Calculator | |
# taxhandler.py | |
import sys | |
fedTax2012 = {} | |
fedTax2012["s"] = ((0,8699,0.1),(8700,35349,0.15),(35350,85649,0.25),(85650,178649,0.28),(178650,388349,0.33),(388350,900000000000,0.35)) | |
fedTax2012["mfj"] = ((0,17399,0.1),(17400,70699,0.15),(70700,142699,0.25),(142700,217449,0.28),(217450,388349,0.33),(388350,900000000000,0.35)) | |
fedTax2012["mfs"] = ((0,8699,0.1),(8700,35349,0.15),(35350,71349,0.25),(71350,108724,0.28),(108725,194174,0.33),(194175,900000000000,0.35)) | |
fedTax2012["hoh"] = ((0,12399,0.1),(12400,47349,0.15),(47350,122299,0.25),(122300,198049,0.28),(198050,388349,0.33),(388350,900000000000,0.35)) | |
vaTax2012 = ((0,3000,0,0.02,0),\ | |
(3001,5000,60,0.03,3000),\ | |
(5001,17000,120,0.05,5000),\ | |
(17001,900000000000,720,0.0575,17000)) # (min,max,flat,%, excess) | |
def FederalTax12Prcnt(maritalstatus="", yearIncome=0): # s = single, mfj = married filing jointly, mfs = married filing separately, hoh = head of houshold | |
""" FederalTax12Prcnt(maritalstatus="", yearIncome=0) Returns current federal tax percentage for 2012. """ | |
try: | |
for x in fedTax2012[maritalstatus]: | |
if x[1] > yearIncome > x[0]: | |
return x[2]; | |
except: | |
return; | |
def FederalTax12Total(maritalstatus="", yearIncome=0): # s = single, mfj = married filing jointly, mfs = married filing separately, hoh = head of houshold | |
""" FederalTax12Total(maritalstatus, yearIncome) Returns total federal tax for the year 2012 """ | |
try: | |
for x in fedTax2012[maritalstatus]: | |
if x[1] > yearIncome > x[0]: | |
return round((x[2] * yearIncome),2); | |
except: | |
return; | |
def VaTax2012YearTotal(yearIncome=0): | |
""" VaTax2012YearTotal(yearIncome) Returns state tax for 2012. """ | |
try: | |
for x in vaTax2012: | |
if x[1] > yearIncome > x[0]: | |
return round((x[2] + x[3] * yearIncome),2); | |
except: | |
return; | |
def ReturnTaxValues(TotalYearsIncome = 0, FilingStatus = "s"): | |
""" Return tuple of all relevant tax values (fed. percent, fed tax, state tax, total tax) """ | |
return (int(100*FederalTax12Prcnt("s",TotalYearsIncome)), # Federal tax percent rate | |
float(FederalTax12Total("s", TotalYearsIncome)), # Federal tax total | |
float(VaTax2012YearTotal(TotalYearsIncome)), # State tax total | |
float(FederalTax12Total("s", TotalYearsIncome) + VaTax2012YearTotal(TotalYearsIncome)) # Combined Federal and State tax | |
) | |
def RunTest(IncVariable = 0.0,CurStVal = "YR"): | |
""" RunTest( Income, TimeHandler) Prints out overall values for the tax year. """ | |
CurTupTax = ReturnTaxValues(IncVariable) | |
print "_-^-" * 10 | |
print "Estimated values given on current income." | |
print "Income: $" + format(IncVariable, ",.2f") | |
print "Federal tax is at " + format(CurTupTax[0], ",d") + r"%" | |
print "Fedral tax for year: $" + format(CurTupTax[1], ",.2f") | |
print "State tax for year: $" + format(CurTupTax[2], ",.2f") | |
print "Total tax for the year equals: $" + format(CurTupTax[3], ",.2f") | |
if CurStVal == "WK": | |
print "Tax for one week: $" + format(CurTupTax[3]/52, ",.2f") | |
print "After taxes are deducted you have $" + format(IncVariable/52 - CurTupTax[3]/52, ",.2f") + " this paycheck." | |
elif CurStVal == "BIWK": | |
print "Tax for biweekly: $" + format(CurTupTax[3]/26, ",.2f") | |
print "After taxes are deducted you have $" + format((IncVariable-CurTupTax[3])/26, ",.2f") + " this paycheck." | |
print "_-^-" * 10 | |
return; | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
for x in range(len(sys.argv)): | |
if sys.argv[x] == "-wk" and len(sys.argv) > x: | |
try: | |
RunTest(float(sys.argv[x+1]) * 52, "WK") | |
except: | |
raise Exception("-wk Not A Valid Number!") | |
break; | |
elif sys.argv[x] == "-biwk" and len(sys.argv) > x: | |
try: | |
RunTest(float(sys.argv[x+1]) * 26,"BIWK") | |
except: | |
raise Exception("-biwk Not A Valid Number!") | |
break; | |
else: | |
if len(sys.argv) == x+1: | |
try: | |
RunTest(float(sys.argv[x]),"YR") | |
continue; | |
except: | |
raise Exception("Not A Valid Number!") | |
else: | |
continue; | |
print "Darn. You don't want this result." | |
break; | |
else: | |
print "_-^-" * 10 | |
print "taxhandler.py" | |
print " Usage: taxhandler ( -wk | -biwk | ) #####" | |
print "_-^-" * 10 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment