cigarettes_after_text
cigarettes_after_text

Reputation: 61

Creating a Conditional Function in Python

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.

Upvotes: 0

Views: 520

Answers (1)

jkr
jkr

Reputation: 19250

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.

Upvotes: 3

Related Questions