Choose the correct answer
Anonymous Quiz
0%
0
0%
1
7%
2
13%
4
0%
7
60%
49
13%
128
7%
None
0%
TypeError
0%
See solution
What will this code do?
def f():
_x = None
def g(x=None):
nonlocal _x
if x is None:
return _x
_x = x
return g
g = f()
print(g(), g(10), g(), g(5), g())
Choose the correct answer
Anonymous Quiz
10%
None None 10 10 5
20%
None 10 10 5 5
30%
None None 10 None 5
10%
None None 10 10 5
10%
None None 10 5 5
20%
None 10 None 5 None
0%
See solution
What will this code do?
def f(x):
y = x ** 2
return y
print(*f.__code__.co_varnames)
What will this code do?
def f(x, y):
f.y = y
f.z = f.y
return x
print(f(1, 2), [x for x in dir(f) if not x.startswith('__')])
Choose the correct answer
Anonymous Quiz
11%
1 2
0%
1 []
0%
1 [2]
33%
1 ['y', 'z']
11%
1 ['x', 'y', 'z']
22%
1 ['x', 'y']
11%
1 ['x', 'z']
0%
NameError
0%
AttributeError
11%
See solution
What will this code do?
def f(arr):
return 0 if not arr else arr[0] + f(arr[1:])
print(f(('a', 'b', 'c', 'd')))
Choose the correct answer
Anonymous Quiz
44%
abcd
0%
None
44%
TypeError
11%
IndexError
0%
ValueError
0%
See solution
What will this code do?
def f(arr):
return arr[0] if len(arr) == 1 else arr[0] + f(arr[1:])
print(f(('a', 'b', 'c', 'd')))
Please select a valid option
Anonymous Quiz
73%
abcd
0%
None
27%
TypeError
0%
IndexError
0%
ValueError
0%
See solution
What will this code do?
def f(arr):
first, *rest = arr
return first if not rest else first + f(rest)
print(f(('H', 'e', 'l', 'l', 'o')))
Choose the correct answer
Anonymous Quiz
79%
Hello
7%
None
0%
TypeError
14%
IndexError
0%
ValueError
0%
See solution
What will this code do?
def f(a: int, b: float) -> int:
return a * int(b)
print(f(5, 2.1))
What will this code do?
def func(a: str, b: int):
return a + b
func(1, 2)
for arg in sorted(func.__annotations__):
print(arg, func.__annotations__[arg])
break
Choose the correct answer
Anonymous Quiz
0%
3
8%
a 1
8%
b 2
42%
a 1 b 2
8%
a <class 'str'>
0%
b <class 'int'>
17%
a <class 'str'> b <class 'int'>
17%
TypeError
0%
SyntaxError
0%
See solution
What will this code do?
def f(x, y):
z = x ** y
return z
print(f.__code__.co_argcount)
Choose the correct answer
Anonymous Quiz
6%
0
6%
1
56%
2
6%
3
11%
None
11%
AttributeError
6%
See solution
What will this code do?
def f(arr):
s = 0
for x in arr:
if not isinstance(x, list):
s += x
else:
s += f(x)
return s
print(f([1, [2, [3, [4, [5]]]]]))