私信  •  关注

Vulpex

Vulpex 最近创建的主题
Vulpex 最近回复了
6 年前
回复了 Vulpex 创建的主题 » Python:查找给定数字列表中的每个Fibonacci序列
FIB = [0,1,1,2,3,5,8,13]

def checkSequence(numArr):
    i = 0
    while i < len(numArr):
        if FIB[i] == int(numArr[i]):
            i += 1
        else:
            return i

numbers = input("Enter your numbers list and use comma to seperate them: ")
numlist = numbers.split(",")
answer = list()
i = 0
while i < len(numlist):
    if int(numlist[i]) == 0:
        ret = checkSequence(numlist[i:])
        answer.append(numlist[i:i+ret])
    i += 1

如您所见,您可以很容易地使用check squence方法检查数组拼接的squence并返回找到的条目数。使用检查序列中的答案,然后可以为您的答案列表创建一个拼接。这将产生您在问题中指定的结果。