Choose your answer
Anonymous Quiz
69%
[(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')]
13%
[(1, 2)]
0%
[(1, 2), ('a', 'b')]
0%
[(1, 'a', 2), (2, 'b', 1)]
19%
See solution
What will this code do?
from functools import reduce
class MyList:
def __init__(self, *args):
self.items = list(args)
def __len__(self):
return reduce(lambda acc, x: acc + (sum(x) if hasattr(x, '__iter__') else x), [x*2 for x in self.items])
my_list = MyList(1, 2, 3, [4, 5])
print(len(my_list))
What will this code do?
a = {1, 2, 9}
b = {2, 3, 9}
c = a & b
c.remove(2)
print(*c)What will this code do?
a = {1, 2}
b = {2, 3}
c = (a | b) - (a & b)
d = a ^ b
print(c == d)What will this code do?
a, b = {1, 2}, {2, 3}
c = a - b
d = b - a
print(*(c & d), *(c | d))What will this code do?
my_list = [1, 2, 3, 4, 5]
r = [x % 3 for x in my_list]
print(sum(r))
What this code do?
class A:
__x = 1
def f(self):
return "f from A"
def g(self):
return "g from A"
class B:
__x = 2
def f(self):
return "f from B"
def g(self):
return "g from B"
class C(A, B):
f = B.f
c = C()
print(c.f(), c.g(), c._A__x, c._B__x)
What this code do?
def intersect(*seqs):
if len(seqs) > 2:
return intersect(seqs[0], intersect(*seqs[1:]))
seq1, seq2 = seqs[0], seqs[1]
res = []
for x in seq1:
if x in seq2:
res.append(x)
return res
x = intersect([1, 2, "a", "b"], (1, 4, "b"), {1, "b", "c"})
print(x)
Choose the correct answer
Anonymous Quiz
31%
[1, 2, 4, 'a', 'b', 'c']
8%
[1, 'b', 'c']
54%
[1, 'b']
0%
[1]
0%
([1, 2, 'a', 'b'], [1, 'b'])
0%
IndexError
8%
Show results
What this code do?
def f(n):
return 0 if n == 0 else 2**n + f(n-1)
print(f(3))
What this code do?
def f():
x = 1
y = 1
def g():
nonlocal x
x, y = 2, 2
g()
print(x, y)
f()
Choose the correct answer
Anonymous Quiz
0%
1 1
11%
1 2
61%
2 1
17%
2 2
6%
NameError
6%
Show results
Given code:
try:
my_x = 1
raise Exception('exception') #1
except Exception as my_err:
print(my_err) #2
my_y = 2
print(my_x) #3
print(my_y) #4
print(my_err) #5