Python:Personal Programme for Practice

Good Evening Friends, I hope outside code is allowed on this forum.As for coding practice I am trying to make a programme for tax calculation.But it is not working. Following is the code for my programme

#Tax-Calc

# In come tax calculation
def calculate_tax(income):
    if (income < 300000):
        tax =(0)  #nil tax
    elif(income > 300001) and (income < 500000):
        tax = (0.1 * (300000 - income))
    elif(income > 500001) and (income < 1000000):
        tax = (0.2 * (1000000 - 300000 - income))
    elif (income > 1000001):
        tax = (0.3 * (1000001 - 300000 - income))
    else:
        pass
x = float(input("Enter Income :"))
print (calculate_tax (x))

I am coding this on python 3.5.When ever I run the programme I get “None” result. Can you point my mistake.

You forgot to return tax.

also all these conditions can be shortened…

def calculate_tax(income):
    if  income < 300000:
        tax =(0)  #nil tax
    elif income < 500000:
        tax = (0.1 * (300000 - income))
    elif   income < 1000000:
        tax = (0.2 * (1000000 - 300000 - income))
    elif  income > 1000001:
        tax = (0.3 * (1000001 - 300000 - income))
    else:
        pass

    return tax

Don’t forget to account for an income of 1000000 or 1000001.

good point! :thumbsup:
almost missed :smiley:

1 Like

Thanks for heads up. I didn’t thought about such scenario

1 Like