Choose the correct answer
Anonymous Quiz
13%
2 True
0%
2 False
20%
11 True
60%
11 False
7%
See solution
What will this code do?
def maker(f, args, kwargs):
return 1 + f(*args, **kwargs)
m1 = maker(lambda a, b: a + b, (5, ), {"b": 2})
m2 = maker(lambda a, b: a * b, [4, 5], {})
print(m1 + m2)
What will this code do?
def f(test, *args):
res = []
for arg in args:
if test(arg):
res.append(arg)
return sum(res)
data = [-4, 2, -1, 5, -6, 3]
negative = lambda x: x < 0
neg = f(negative, *data)
positive = lambda x: x > 0
pos = f(positive, *data)
print(neg, pos)
Choose the correct answer
Anonymous Quiz
0%
-1
0%
0 0
0%
-4 2
9%
[-4, -1, -6] [2, 5, 3]
27%
[-11] [10]
0%
[10] [-11]
64%
-11 10
0%
-10 11
0%
See solution
What will this code do?
x = 1
def f():
def g():
nonlocal x
print(x)
x += 1
return g
Choose your answer
Anonymous Quiz
16%
1
26%
2
0%
None
21%
SyntaxError
32%
UnboundLocalError
5%
NameError
0%
See solution
What will this code do?
def f(a, b, c, d, e):
print(a, b, c, d, e)
f(1, *(3,), c=10, **{"d": 5, "e": 100})
Choose your answer
Anonymous Quiz
7%
1 10 3 5 100
71%
1 3 10 5 100
7%
1 3 None 10 5 100
7%
SyntaxError
7%
TypeError
0%
NameError
What will this code do?
def f(s:str = "1") -> int:
return s * 2
print(f(), isinstance(f(), int))
Choose the correct answer
Anonymous Quiz
17%
2 True
0%
2 False
8%
11 True
75%
11 False
0%
See solution
What will this code do?
def maker(f, args, kwargs):
return 1 + f(*args, **kwargs)
m1 = maker(lambda a, b: a + b, (5, ), {"b": 2})
m2 = maker(lambda a, b: a * b, [4, 5], {})
print(m1 + m2)
What will this code do?
def f(test, *args):
res = []
for arg in args:
if test(arg):
res.append(arg)
return sum(res)
data = [-4, 2, -1, 5, -6, 3]
negative = lambda x: x < 0
neg = f(negative, *data)
positive = lambda x: x > 0
pos = f(positive, *data)
print(neg, pos)
Choose the correct answer
Anonymous Quiz
0%
-1
0%
0 0
0%
-4 2
67%
[-4, -1, -6] [2, 5, 3]
0%
[-11] [10]
0%
[10] [-11]
33%
-11 10
0%
-10 11
0%
See solution
What will this code do?
def f(transform, *args):
res = args[0]
for arg in args[1:]:
res = transform(res, arg)
return res
data = [-4, 2, -1, 5, -6, 3]
func = lambda x, n: x * (-1)**n
print(f(func, *data))
Choose the correct answer
Anonymous Quiz
0%
-720
33%
-4
11%
-1
11%
1
33%
4
11%
[4, -2, 1, -5, 6, -3]
0%
See solution
What will this code do?
def mintwo(*args):
tmp = list(args)
tmp.sort()
return tmp[0], tmp[1]
data = [8, -4, 5, -2, 9, 3, -98]
print(*mintwo(*data))
Choose the correct answer
Anonymous Quiz
7%
-102
0%
-98
7%
-2
14%
8 -4
64%
-98 -4
0%
9 8
0%
(8, -4)
7%
(-98, -4)
0%
(9, 8)
0%
See solution
What will this code do?
def f(*args):
result = []
for x in args[0]:
if x in result:
continue
for word in args[1:]:
if x not in word:
break
else:
result.append(x)
return ''.join(result)
s1, s2, s3= "message", "massage", "mask"
print(f(s1, s2, s3))