-1

我正在编写的部分代码有问题(如标题中所述)。所有的 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)
4

1 回答 1

2

这一行:

tax = (0.10 * a) + (0.15 * b) + (0.25 * c) + (0.28 * (income - c) 

你忘了)在最后添加一个。

然后 Python 将下一行解释为上一行的延续,因此会出现 SyntaxError。

于 2013-10-02T06:20:01.917 回答