Every line of 'fibonacci recursion python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
6 def test_fib(self, func): 7 result = [] 8 expected = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] 9 for i in range(len(expected)): 10 result.append(func(i)) 11 assert_equal(result, expected) 12 print('Success: test_fib')
14 def fibonacci(x: int): 15 if x < 0: 16 return -1 17 if x == 0: 18 return 0 19 cache = [0] * (x + 1) 20 for i in range(1, len(cache)): 21 cache[i] = -1 22 cache[1] = 1 23 return fibonacci_recur(x, cache)