Skip to content

Fibonacci numbers

Python double recursion

Same task in: GoRust

Flowchart (ISO 5807)

YesNoStartInput nn < 2Return nEndReturn fib(n − 1) + fib(n − 2)EndFigure 1 — fib

Source code

Python
def fib(n):
    if n < 2:
        return n
    return fib(n - 1) + fib(n - 2)

The editor opens with this code — change it and the chart redraws.

Language
Python
Constructs
double recursion
Topic
Recursion
Formats
Word, Visio, draw.io, PDF, SVG

Related examples