Fibonacci sequence ================== Example code ------------ .. interactive_code_block:: :caption: Straightforward version without trickery length = 15 a = 0 b = 1 for i in range(length): print(a, end=' ') c = a + b a = b b = c .. interactive_code_block:: :caption: Straightforward, compacter version with some trickery length = 15 a, b = 0, 1 # Creating and unpacking a tuple in a single line for i in range(length): print(a, end=' ') a, b = b, a+ b Exercise 1 ---------- Complete the code by replacing ``# ..........``. .. interactive_code_block:: :caption: Create a function that prints the sequence def fibonacci(length): # .......... # .......... # .......... fibonacci(15) .. def fibonacci(length): a, b = 0, 1 for i in range(length): print(a, end=' ') a, b = b, a+ b fibonacci(15) Exercise 2 ---------- Complete the code by replacing ``# ..........``. .. interactive_code_block:: :caption: Create a function that returns the sequence def fibonacci(length): # .......... # .......... # .......... result = fibonacci(15) print(result) .. def fibonacci(length): result = [] a, b = 0, 1 for i in range(length): result.append(a) a, b = b, a+ b return result result = fibonacci(15) print(result)