Income tax code

90 views
Skip to first unread message

sunil paudel

unread,
Sep 14, 2016, 1:04:57 AM9/14/16
to Python GCU Forum
How can i write income tax code
Tax Calculator
Incremental Income                                                                         Tax Rate
0 to $30,000.00                                                                                    0%
$30,000.01 to $50,000                                                                           10%
$50,000.01 to $100,000                                                                           20%
$100,000 .01 to $200,000                                                                        30%
$200,000.01 to $250,000                                                                         35%   
>$250,000.01                                                                                          40%

Note that the above ranges are not total  income but additional income. For example, if one earns $125,000 per year, then there is no tax on the first $30,000. The next $20,000 is taxed at a rate of 10%, the next $50,000 is taxed at a rate of 20%, and the remaining $25,000 is taxed at a rate of 30%.

Richard Loy

unread,
Sep 16, 2016, 2:14:45 PM9/16/16
to Python GCU Forum
Hi Sunil, there are many ways to do this quickest but more coding involved is an if statement to check the value of income and the tax bracket then run a tax calculation (see below). There are of course easier ways in which you Don't Repeat Yourself, this way is more straight forward.

class Tax:

    def main(self):

        self.total_tax = 0.0
        self.income = float(input("Enter Income:"))
        print("Total Income: $%0.2f" % (self.income))

        if self.income > 250000:
            #calculate tax for income over $250000 @40%
            self.total_tax += self.calc_tax(self.income-250000, 40)
            #calculate tax for income over $200000 @35%
            self.total_tax += self.calc_tax(50000, 35)
            #calculate tax for income over $100000 @30%
            self.total_tax += self.calc_tax(100000, 30)
            #calculate tax for income over $50000 @20%
            self.total_tax += self.calc_tax(50000, 20)
            #calculate tax for income over $30000 @10%
            self.total_tax += self.calc_tax(20000, 10)
            print("Total tax: $%0.2f" % (self.total_tax))
        if self.income > 200000 and self.income <= 250000:
            #calculate tax for income over $200000 @35%
            self.total_tax += self.calc_tax(self.income - 200000, 35)
            #calculate tax for income over $100000 @30%
            self.total_tax += self.calc_tax(100000, 30)
            #calculate tax for income over $50000 @20%
            self.total_tax += self.calc_tax(50000, 20)
            #calculate tax for income over $30000 @10%
            self.total_tax += self.calc_tax(20000, 10)
            print("Total tax: $%0.2f" % (self.total_tax))
        if self.income > 100000 and self.income <= 200000:
            #calculate tax for income over $100000 @30%
            self.total_tax += self.calc_tax(self.income - 100000, 30)
            #calculate tax for income over $50000 @20%
            self.total_tax += self.calc_tax(50000, 20)
            #calculate tax for income over $30000 @10%
            self.total_tax += self.calc_tax(20000, 10)
            print("Total tax: $%0.2f" % (self.total_tax))
        if self.income > 50000 and self.income <= 100000:
            #calculate tax for income over $50000 @20%
            self.total_tax += self.calc_tax(self.income - 50000, 20)
            #calculate tax for income over $30000 @10%
            self.total_tax += self.calc_tax(20000, 10)
            print("Total tax: $%0.2f" % (self.total_tax))
        if self.income > 30000 and self.income <= 50000:
            #calculate tax for income over $30000 @10%
            self.total_tax += self.calc_tax(self.income - 30000, 10)
            print("Total tax: $%0.2f" % (self.total_tax))

    def calc_tax(self, income, tax_rate):
            tax = income/tax_rate
            return tax
           
if __name__ == "__main__":
    Tax().main()
Reply all
Reply to author
Forward
0 new messages