File tree Expand file tree Collapse file tree 1 file changed +31
-4
lines changed Expand file tree Collapse file tree 1 file changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -89,11 +89,36 @@ def fib_iterative(n: int) -> list[int]:
8989
9090
9191def fib_recursive (n : int ) -> list [int ]:
92+ """
93+ Calculate the first n (0-indexed) Fibonacci numbers using recursion.
94+
95+ Args:
96+ n (int): The number of Fibonacci terms to generate.
97+
98+ Returns:
99+ list[int]: A list of the first n Fibonacci numbers.
100+
101+ Examples:
102+ >>> fib_recursive(0)
103+ [0]
104+ >>> fib_recursive(1)
105+ [0, 1]
106+ >>> fib_recursive(5)
107+ [0, 1, 1, 2, 3, 5]
108+ >>> fib_recursive(-1)
109+ Traceback (most recent call last):
110+ ...
111+ ValueError: n is negative
92112 """
93- Calculates the first n (0-indexed) Fibonacci numbers using recursion
94- >>> fib_iterative(0)
95- [0]
96- >>> fib_iterative(1)
113+
114+ def fib_recursive_term (i : int ) -> int :
115+ """
116+ Calculates the i-th (0-indexed) Fibonacci number using recursion
117+ >>> fib_recursive_term(0)
118+ 0
119+ >>> fib_recursive_term(1)
120+ 1
121+ >>> fib_iterative(1)
97122 [0, 1]
98123 >>> fib_iterative(5)
99124 [0, 1, 1, 2, 3, 5]
@@ -112,6 +137,8 @@ def fib_recursive_term(i: int) -> int:
112137 0
113138 >>> fib_recursive_term(1)
114139 1
140+ >>> fib_recursive_term(5)
141+
115142 >>> fib_recursive_term(5)
116143 5
117144 >>> fib_recursive_term(10)
You can’t perform that action at this time.
0 commit comments