Module 4 Quiz
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
22 Questions
1.2 points
1.2
Question 1
1.
What is the output of the following snippet?
def f(x): if x == 0: return 0 return x + f(x-1)
print(f(4))
What is the output of the following snippet?
def f(x):
if x == 0:
return 0
return x + f(x-1)
print(f(4))
0.8 points
0.8
Question 2
2.
A built-in function is a function which:
A built-in function is a function which:
1 point
1
Question 3
3.
The fact that tuples belong to sequence types means that:
The fact that tuples belong to sequence types means that:
1 point
1
Question 4
4.
A function defined in the following way: (Select two answers)
def function(x=0): return x
A function defined in the following way: (Select two answers)
def function(x=0):
return x
1 point
1
Question 5
5.
The following snippet:
def func(a,b): return a ** a
print(func(2))
The following snippet:
def func(a,b):
return a ** a
print(func(2))
1 point
1
Question 6
6.
Select the true statements about the try-except block in relation to the following example. (Select two answers)
try: # Some code is here...except: # Some code is here...
Select the true statements about the try-except block in relation to the following example. (Select two answers)
try:
# Some code is here...
except:
# Some code is here...
1 point
1
Question 7
7.
What is the output of the following snippet?
def any(): print(var + 1, end='')
var = 1any()print(var)
What is the output of the following snippet?
def any():
print(var + 1, end='')
var = 1
any()
print(var)
1 point
1
Question 8
8.
What is the output of the following code?
try: value = input("Enter a value: ") print(value/value)except ValueError: print("Bad input....")except ZeroDivisionError: print("Very bad input....")except TypeError: print("Very very bad input....")except: print("Booo!")
What is the output of the following code?
try:
value = input("Enter a value: ")
print(value/value)
except ValueError:
print("Bad input....")
except ZeroDivisionError:
print("Very bad input....")
except TypeError:
print("Very very bad input....")
except:
print("Booo!")
1 point
1
Question 9
9.
Which of the following lines properly starts a function using two parameters, both with zeroed default values?
Which of the following lines properly starts a function using two parameters, both with zeroed default values?
1 point
1
Question 10
10.
What is the output of the following snippet?
def fun(x): x += 1 return x
x=2x=fun(x+1)print(x)
What is the output of the following snippet?
def fun(x):
x += 1
return x
x=2
x=fun(x+1)
print(x)
1 point
1
Question 11
11.
The following snippet:
def func_1(a): return a**a
def func_2(a): return func_1(a) * func_1(a)
print(func_2(2))
The following snippet:
def func_1(a):
return a**a
def func_2(a):
return func_1(a) * func_1(a)
print(func_2(2))
1 point
1
Question 12
12.
What is the output of the following snippet?
def fun(x): global y y = x * x return y
fun(2)print(y)
What is the output of the following snippet?
def fun(x):
global y
y = x * x
return y
fun(2)
print(y)
1.2 points
1.2
Question 13
13.
What code would you insert instead of the comment to obtain the expected output?
Expected output:
abc
Code:
dictionary = {}my_list = ['a','b','c','d']
for i in range(len(my_list) - 1) : dictionary[my_list[i]] = (my_list[i], )
for i in sorted (dictionary.keys()): k = dictionary[i] # Insert your code here.
What code would you insert instead of the comment to obtain the expected output?
Expected output:
a
b
c
Code:
dictionary = {}
my_list = ['a','b','c','d']
for i in range(len(my_list) - 1) :
dictionary[my_list[i]] = (my_list[i], )
for i in sorted (dictionary.keys()):
k = dictionary[i]
# Insert your code here.
1 point
1
Question 14
14.
What is the output of the following snippet?
my_list = ['Mary', 'had', 'a', 'little', 'lamb']
def my_list(my_list): del my_list[3] my_list[3] = 'ram'
print(my_list(my_list))
What is the output of the following snippet?
my_list = ['Mary', 'had', 'a', 'little', 'lamb']
def my_list(my_list):
del my_list[3]
my_list[3] = 'ram'
print(my_list(my_list))
1 point
1
Question 15
15.
What is the output of the following snippet?
def fun(inp=2, out=3): return inp * out
print(fun(out=2))
What is the output of the following snippet?
def fun(inp=2, out=3):
return inp * out
print(fun(out=2))
1 point
1
Question 16
16.
What is the output of the following snippet?
def fun(x): if x % 2 == 0: return 1 else: return
print(fun(fun(2)) + 1)
What is the output of the following snippet?
def fun(x):
if x % 2 == 0:
return 1
else:
return
print(fun(fun(2)) + 1)
1 point
1
Question 17
17.
What is the output of the following snippet?
dictionary = {'one' : 'two' , 'three' : 'one', 'two' : 'three'}v = dictionary['one']
for k in range(len(dictionary)): v = dictionary[v]
print(v)
What is the output of the following snippet?
dictionary = {'one' : 'two' , 'three' : 'one', 'two' : 'three'}
v = dictionary['one']
for k in range(len(dictionary)):
v = dictionary[v]
print(v)
1 point
1
Question 18
18.
What is the output of the following snippet?
def fun(x, y, z): return x + 2 * y + 3 * z
print( fun(0, z = 1, y = 3) )
What is the output of the following snippet?
def fun(x, y, z):
return x + 2 * y + 3 * z
print( fun(0, z = 1, y = 3) )
1 point
1
Question 19
19.
Assuming that my_tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction:
my_tuple[1] = my_tuple[1] + my_tuple[0]
Assuming that my_tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction:
my_tuple[1] = my_tuple[1] + my_tuple[0]
1 point
1
Question 20
20.
Which of the following statements are true? (Select two answers)
Which of the following statements are true? (Select two answers)
1 point
1
Question 21
21.
Which one of the following lines properly starts a parameterless function definition?
Which one of the following lines properly starts a parameterless function definition?
1 point
1
Question 22
22.
What is the output of the following snippet?
tup = (1, 2, 4, 8)tup = tup[1:-1]tup = tup[0]
print(tup)
What is the output of the following snippet?
tup = (1, 2, 4, 8)
tup = tup[1:-1]
tup = tup[0]
print(tup)