Every line of 'fibonacci string in 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 py_fibonacci(n): 7 """https://stackoverflow.com/a/52133289/2536357""" 8 i = 0 9 nextterm = 1 10 present = 1 11 previous = 0 12 13 while i < n: 14 nextterm = present + previous 15 present = previous 16 previous = nextterm 17 i = i + 1 18 19 return nextterm
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
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)