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))
Choose the correct answer
Anonymous Quiz
0%
4
5%
6
65%
9
10%
27
5%
TypeError
10%
SyntaxError
5%
See solution
Which expression would be equivalent for a ternary operator
"B if a else с", considering that the variables b and c contains some objects, and the variable a - a boolean value.
"B if a else с", considering that the variables b and c contains some objects, and the variable a - a boolean value.
Anonymous Quiz
0%
a or b and c
10%
a and b and c
20%
a or b or c
25%
a or c and b
25%
a and b or с
5%
a and c or b
15%
See solution
What will this code do?
f = (lambda x, y: x if х < y else y)
z1 = f('b', 'а')
z2 = f('а', 'b')
print(z1 == z2)
What will this code do?
def f(a: int = 5, b: int = 3, c: int = 4) -> int:
return a + b + c
print(f(2.5, b=2))