我正在尝试基于一系列条件语句在python中创建减税计算功能。我的第一个条件“ if”语句出现语法错误,不确定原因。
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
[如果有人能对我可能犯的语法错误提供任何见解,那将是非常好的。我是编程的初学者。
用filing_category = 1
替换filing_category == 1
。对=
语句中的if
的其他实例执行此操作。
单个=
是赋值运算符,将值分配给变量。测试两个事物是否相等的相等运算符为==
。有关更多信息,请参见python documentation on operators。