Answer to Question #255749 in Python for Emre

Question #255749

Write a Python function, named “find_fibonacci”, which accepts a list as input.  The function will find and return the elements that satisfy the Fibonacci property: 


Example : Input list : [2, 8, 4, 6, 1, 7, 8, 4, 7, 9, 4, 13]  

Returned list : [[6,1,7], [1,7,8], [9,4,13]]   




1
Expert's answer
2021-10-29T00:54:21-0400

Source code



def find_fibonacci(list1):
    list2=[]
    for i in range(len(list1)):
        fib=[]
        if (list1[i-2]+list1[i-1]==list1[i]):
            fib.append(list1[i-2])
            fib.append(list1[i-1])
            fib.append(list1[i])
            list2.append(fib)
    return list2
print(find_fibonacci([2, 8, 4, 6, 1, 7, 8, 4, 7, 9, 4, 13]))

Output


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS