我试图在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相关问题 更多 >
编程相关推荐