quiz 5 Flashcards
What is the output of the following?
def f(n):
return 2*n + f(n-1)
print(f(3))
f runs forever and causes StackOverflowError
Consider a Python function f(x, y). For which data types of parameters x and y is it possible to get the same result as passing by reference?
dictionary and set
The mechanism for passing parameters to a function in Python is:
call by assignment
What is the base case for the following recursive function:
def f(b, q, n):
if n == 0:
return 0
else:
return b*q**(n-1) + f(b, q, n-1)
print(f(b=2, q=3, n=4))
n is 0
What is the result of the following:
def f(n):
if n==1:
return 1
else:
return 2**n*f(n-1)
print(f(3))
32
Arguments to functions always appear within:
parentheses: ( )
What data type is used when returning multiple results from a function?
tuple
What is the output of the following code?
def g(n, m):
if n <= 0:
return m
else:
return g(n-1, m+1)
print(g(2, 1))
3
What Python statement allows to suspend function execution and resume it for next call(s)?
yield
recursive functions require more computer resources and more execution time, whereas non-recursive require more lines of code
true