gekko2670 - 1 year ago 93
Python Question

# Python raw input function for tax calculation

I am trying to make a simple calculator for working out the tax due on a salary. Please see the code below:

``````Traceback (most recent call last):
File "python", line 13
elif salary > 11000 and salary < 43000:
^
SyntaxError: invalid syntax
``````

CODE:

``````salary = raw_input ("What is your salary?")

print "So your gross annual salary is %r GBP" % (salary)
print "\nNow we need to calculate what your net salary is."

def taxes(salary):

salary >= 0
while true:
if salary < 11000:
tax = 0
elif salary > 11000 and salary < 43000:
tax = (0.2 * income) - 2200
elif salary > 43000 and salary < 150000:
tax = (0.4 * (salary - 43000)) + 6400
elif salary > 150000:
tax = ((salary - 150000) * 0.45) + 6400 + 42800
return tax
``````

step1 : the salary data type should be of int, to correct..use the following code

step 2: Indentation is compulsory in python, so indent your code very well

step 3: Add an else statement after the conditional statements

step 4: indent return statement

change your code to this one

``````salary = int(raw_input ("What is your salary?"))

print "So your gross annual salary is %r GBP" % (salary)
print "\nNow we need to calculate what your net salary is."

def taxes(salary):

salary >= 0
while true:
if salary < 11000:
tax = 0
elif salary > 11000 and salary < 43000:
tax = (0.2 * income) - 2200
elif salary > 43000 and salary < 150000:
tax = (0.4 * (salary - 43000)) + 6400
elif salary > 150000:
tax = ((salary - 150000) * 0.45) + 6400 + 42800
else :
tax = undefined
return tax
``````