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]]]]]))
Choose the correct answer
Anonymous Quiz
7%
0
13%
1
67%
15
13%
120
0%
None
0%
TypeError
0%
See solution
👍1
What will this code do?
from collections.abc import Iterable
def f(arr):
s = 0
items = list(arr)
while items:
first = items.pop(0)
if not isinstance(first, Iterable):
s += first
else:
items.extend(first)
return s
print(f((1, (2, (3, (4, (5)))))))
What will this code do?
def f(L):
s = ''
items = list(L)
while items:
first = items.pop(0)
if isinstance(first, str):
s += first
else:
items[:0] = first
return s
print(f(('a', ('b', ('c', ('d', 'e'))))))
What will this code do?
def f(a: int = 2, b: int = 2) -> int:
return a ** b
print(f(3))
Choose the correct answer
Anonymous Quiz
14%
4
0%
6
64%
9
14%
27
7%
TypeError
0%
SyntaxError
0%
See solution
What will this code do?
def f(a: int = 2, b: int = 2) -> int:
return a ** b
print(f(3))