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
What will this code do?
class A:
pass
class B(A):
pass
a = A()
b = B()
print(isinstance(b, A), isinstance(a, B))
Choose your answer
Anonymous Quiz
29%
True True
50%
True False
14%
False True
0%
False False
7%
See solution
Choose your answer
Anonymous Quiz
22%
True True
22%
True False
11%
False True
6%
False False
39%
TypeError
0%
See solution
What will this code do?
from random import random
try:
a = random() - 0.5
a = a/0
print(a, end=" ")
except:
print("err", end=" ")
finally:
print(a/a)
Choose your answer
Anonymous Quiz
0%
-inf 1.0
0%
0 1.0
67%
err 1.0
0%
inf 1.0
17%
ZeroDivisionError
0%
None 1.0
8%
nan 1.0
8%
See solution