0

I'm trying to create a tax deductions calculation function in python based on a series of conditional statements. I am getting a syntax error on my first conditional "if" statement and am unsure why.

1 = 'single'
2 = 'married filing jointly'
3 = 'head of household'

def deductions(income, filing_category): ## define function

    if ((filing_category = 1) and (income >= 12200)):
        return income - 12200
    elif((filing_category = 2) and (income >= 24400)):
        return income - 24400
    elif((filing_category = 3) and (income >= 18350)):
        return income - 18350
    else:
        return 'no taxes due'

q = deductions(10000, 1) ## call function
print(q) ## print result

If anyone could offer any insight into what syntactical errors I may be making, that would be great. I'm a beginner to programming.

2
  • 1
    Use '==' instead of '=' in if condition. Commented Feb 10, 2020 at 3:23
  • Have you hear about == before? You have to use that inside if to check equality. Further, 1 = 'single' can't be a valid syntax in any language Commented Feb 10, 2020 at 3:23

1 Answer 1

3

Replace filing_category = 1 with filing_category == 1. Do this for other instances of = in your if statements.

The single = is the assignment operator, assigning a value to a variable. The equality operator, which tests if two things are equal, is ==. Refer to the python documentation on operators for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.