# -*- coding: utf-8 -*- from decimal import * print "Tax Calculator" grossincome = raw_input("Enter your taxable income for the year: ") # There should be 1 more rate than brackets. # 0 - 8375 is taxed at 10% # 8375 to 34000 is taxed at 15% # and so on # data from http://www.moneychimp.com/features/tax_brackets.htm brackets = [8375,34000,82400,171850,373650] rates = [Decimal('.1'),Decimal('.15'),Decimal('.25'),Decimal('.28'),Decimal('.33'),Decimal('.35')] tax = 0 n = 0 income=int(grossincome) previousbrackets = 0 def calculatepartialtax(bracket, rate, income): partialtax = 0 if income-(bracket + previousbrackets) > 0: partialtax = bracket * rate elif income - previousbrackets > 0: partialtax = (income - previousbrackets) * rate return partialtax for bracket in brackets: rate = rates.pop(0) n = bracket tax = tax + calculatepartialtax(bracket, rate, income) previousbrackets = previousbrackets + bracket tax = tax + calculatepartialtax(n, rates[0], income) print "Federal taxes owed at 2010 rates: " + str(tax)