我在这做错了什么?(Python)

时间:2017-03-04 04:31:18

标签: python-3.x

这是我的代码

def almostIncreasingSequence(sequence):
    def count(sequence, item):
        found = 0
        for i in sequence:
            if i == item:
                found += 1
        return (found)
    def removeItemFromArray(sequence, item):
        n = []
        for i in sequence:
            if i != item:
                n.append(i)
        return (n)
    def isIncreasing(sequence):
        if sorted(sequence) == sequence:
            return (True)
        else:
            return (False)
    count = 0
    for i in range(len(sequence) - 1):
        if sequence[i] >= sequence[i + 1]:
            count += 1
    for i in sequence:
        sr = removeItemFromArray(sequence, i)
        if (count(sequence, i) == 1 and count == 1 and isIncreasing(sr) == True) or (len(sequence) == 2 and count(sequence, i) == 2):
            return (True)
    else:
        return (False)
print (almostIncreasingSequence([1,3,2,1]))

这是我的错误

  

追踪(最近一次通话):         文件“C:/Users/Harry/Documents/randompythonprograms/almostincreasingsequence.py”,第29行,           print(almostIncreasingSequence([1,3,2,1]))         文件“C:/Users/Harry/Documents/randompythonprograms/almostincreasingsequence.py”,第25行,在几乎增加的序列中           if(count(sequence,i)== 1 and count == 1 and isIncreasing(sr)== True)或(len(sequence)== 2 and count(sequence,i)== 2):       TypeError:'int'对象不可调用

1 个答案:

答案 0 :(得分:2)

您同时拥有一个名为count的函数和变量。你将不得不重命名其中一个。