我正在编写的部分代码有问题(如标题中所述)。所有的 elif 都在运行到第 10 行的那个(即 elif inc <= e 和 inc > d:),这就是 IDLE 中突出显示的错误。这是代码:
def calc(a,b,c,d,e,f):
if inc <= a and inc >= 0:
tax = 0.10 * income
elif inc <= b and inc > a:
tax = (0.10 * a) + (0.15 * (income - a))
elif inc <= c and inc > b:
tax = (0.10 * a) + (0.15 * b) + (0.25 * (income - b))
elif inc <= d and inc > c:
tax = (0.10 * a) + (0.15 * b) + (0.25 * c) + (0.28 * (income - c)
elif inc <= e and inc > d:
tax = (0.10 * a) + (0.15 * b) + (0.25 * c) + (0.28 * d) + (0.33 * \
(income - d))
elif inc <= f and inc > e:
tax = (0.10 * a) + (0.15 * b) + (0.25 * c) + (0.28 * d) + (0.33 * \
e) + (0.35 * (income - e))
elif inc > f:
tax = (0.10 * a) + (0.15 * b) + (0.25 * c) + (0.28 * d) + (0.33 * \
e) + (0.35 * f) + (0.396 * (income - f)
tax_str = str(tax)