Which function declaration will not throw an error?
Anonymous Quiz
50%
def f(a, b=1, *c=(2,), **d):pass
13%
def f(a, b, **c, d):pass
38%
def f(a=1, b=2, c):pass
0%
def f(a=1, *b, c):pass
0%
def f(a=1, **b, c):pass
0%
def f(**a, b=1, c):pass
0%
See solution
What will this code do?
def f(s:str = "1") -> int:
return s * 2
print(f(), isinstance(f(), int))
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 your answer
Anonymous Quiz
0%
-1
0%
0 0
0%
-4 2
33%
[-4, -1, -6] [2, 5, 3]
22%
[-11] [10]
0%
[10] [-11]
44%
-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(int(f(func, *data)))
Choose your answer
Anonymous Quiz
0%
-720
38%
-4
0%
-1
13%
1
25%
4
13%
[4, -2, 1, -5, 6, -3]
13%
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 your answer
Anonymous Quiz
0%
-102
0%
-98
8%
-2
15%
8 -4
69%
-98 -4
0%
9 8
0%
(8, -4)
0%
(9,8)
8%
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))
👍1
Choose your answer
Anonymous Quiz
9%
mesagk
9%
mssa
27%
msa
27%
mesag
9%
message
0%
massage
0%
mask
9%
messagemassagemask
0%
empty line
9%
See solution
👍1
What is the preferred way to check that the variable `a` is associated with None?
Anonymous Quiz
14%
if not a:
7%
if a == None:
57%
if a is None:
14%
if bool(a) == False:
7%
if bool(a) is False:
0%
See solution
What will this code do?
def f(*args):
result = []
for x in args[0]:
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))
Choose your answer
Anonymous Quiz
20%
mesagk
40%
mssa
10%
msa
0%
mesag
20%
message
0%
massage
0%
mask
0%
messagemassagemask
10%
empty line
0%
See solution
What will this code do?
def f(*args):
res = ""
l = len("".join(args[:-1]))
for i, s in enumerate("".join(args)):
if i > l:
res += s
return res
s1, s2, s3= "one", "two", "three"
print(f(s1, s2, s3))
Choose your answer
Anonymous Quiz
18%
three
45%
hree
0%
two
0%
wo
9%
one
0%
ne
9%
onetwothree
9%
newohree
9%
See solution
What will this code do?
def f(*args):
result = []
for seq in args:
for x in seq:
if not x in result:
result.append(x)
return ''.join(result)
s1, s2, s3 = "message", "massage", "mask"
print(f(s1, s2, s3))
Choose your answer
Anonymous Quiz
54%
mesagk
0%
mssa
0%
msa
0%
mesag
0%
message
0%
massage
8%
mask
23%
messagemassagemask
15%
empty line
0%
See solution