May 2019
Beginner
528 pages
29h 51m
English
11.1 What does the following code do?
In [1]: def mystery(a, b):...: if b == 1:...: return a...: else:...: return a + mystery(a, b - 1)...:In [2]: mystery(2, 10)Out[2]: ?????
11.2 Find the logic error(s) in the following recursive function, and explain how to correct it (them). This function should find the sum of the values from 0 to n.
In [3]: def sum(n):...: if n == 0:...: return 0...: else:...: return n + sum(n)...:
11.3 What does the following code do?
In [4]: def mystery(a_array, size):...: if size == 1:...: return a_array[0]...: else:...: return a_array[size - 1] + mystery(a_array, size - 1)...:In [5]: import numpy as npIn [6]: numbers = np.arange(1, 11)In [7]: mystery(numbers, len(numbers)) ...
Read now
Unlock full access