为什么会出现语法错误?

时间:2015-01-27 05:37:45

标签: python-3.x

CutPrices=[(1,5),(2,6),(3,2)]
CutPrices=sorted(CutPrices)

RodLength=int(input("Enter Rod Length =>"))

def CutRod(p, n):
    if n == 0:
        return 0
    q =float(-inf)
    for i in range(1,n+1):
            q = max(q, p[i-1][1] + CutRod(p, n-p[i-1][0])
    return q

print(CutRod(CutPrices,RodLength))

1 个答案:

答案 0 :(得分:0)

你在这一行上缺少右括号:

q = max(q, p[i-1][1] + CutRod(p, n-p[i-1][0]))
                                             ^