``````#calculate the amout of tax due to the tax given income

def calTax( income ):
tax = 0
if income <25000:
tax = income * 0.25
elif income > 25000 and income < 50000:
tax = 25000 * 0.25 + (income - 25000) * 0.33
elif income > 50000:
tax = 25000 * 0.25 + 25000 * 0.33 + (income - 50000) * 0.5
return tax

def main ():
taxableIncome = int(raw_input("Enter taxable income: "))
governmentTake = calTax ( taxableIncome )
print "The tax on \$%0.2f is \$%0.2f" % (taxableIncome,governmentTake)

main()``````

Ive written this program but im not sure if it is calculating the tax properly.

Any help would be great

It looks more or less correct, it at least looks as if it should calculate the tax correctly. The only obvious problems I can see are the conditions in your if..elif.. block, which needs a couple of minor tweaks.

At the moment, if you enter the value 50000 you'll get 0 returned as the amount of tax due. As mentioned, this is down to the conditions in your if..elif statement block. You need to use <= instead of < in a few places. In fact your if..elif block can actually be simplified a little.

For example, you could do this:

``````#calculate the amout of tax due to the tax given income

def calTax( income ):
tax = 0
if income <= 25000: # less than or equal to 25000
tax = income * 0.25
elif income <= 50000: # less than or equal to 50000
tax = 25000 * 0.25 + (income - 25000) * 0.33
else: # must be greater than 50000
tax = 25000 * 0.25 + 25000 * 0.33 + (income - 50000) * 0.5
return tax

def main ():
taxableIncome = int(raw_input("Enter taxable income: "))
governmentTake = calTax ( taxableIncome )
print "The tax on \$%0.2f is \$%0.2f" % (taxableIncome,governmentTake)

main()``````

Cheers for now,
Jas.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.