Fibonacci sequence — highlighted = F(N)
Select N
1def fib(n):
2a, b = 0, 1
3for _ in range(n): a, b = b, a+b
4return a
6
Each term is the sum of the previous two. Use a function with a loop — track two running values, no array needed.
Start 0, 1. Repeat: next = a+b, then slide the window.
You return the Nth term of a sequence where each number is the sum of the previous two numbers.
Used in recurrence modelling, algorithm practice, growth simulations, and dynamic programming examples.
a, b = 0, 1 — first two Fibonacci numbers.a, b = b, a + b.a holds F(N). No array needed — O(1) space.Nature uses Fibonacci in flower petal counts, spiral shells, and stock analysis (Fibonacci retracement levels). Algorithmic trading frameworks call fib(n) thousands of times per second.