0
#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

2
Contributors
1
Reply
5
Views
7 Years
Discussion Span
Last Post by JasonHippy
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.