👍1
👍1
What will this code do?
class A: pass
class B(A): pass
class C1(A): pass
class C2: pass
class D1(B, C1): pass
class D2(B, C2): pass
X = list(D1.__mro__)
Y = list(D2.__mro__)
print(X[3] is Y[2])
👍1
Choose your answer
Anonymous Quiz
35%
True
23%
False
12%
TypeError
12%
AttributeError
19%
See solution
👍1
What will this code do?
class MyList(list):
def __getitem__(self, index):
return super().__getitem__(index) * 2
m = MyList([1, 2])
print([m[i] + x for i, x in enumerate(m)])
👍1
Choose your answer
Anonymous Quiz
0%
[1, 2]
12%
[1, 2, 1, 2]
42%
[2, 4]
35%
[3, 6]
0%
TypeError
4%
IndexError
8%
See solution
👍2
What will this code do?
def invertdict(D):
def keysof(V):
return sorted(K for K in D.keys() if D[K] == V)
return {V: keysof(V) for V in set(D.values())}
D = {'x': 'a', 'y': 'b', 'z': 'a'}
print(invertdict(D))
What will this code do?
s = "Hello, world!"
s.find("world", 0, 7) + s.find("world", 5)
🤯2🔥1
What will this code do?
class D:
__slots__ = ['a', 'b']
d = D()
d.a = 1
f = lambda attr: getattr(d, attr, '*')
print(f('a'), f('b'), f('__dict__'))
👍1
Choose your answer
Anonymous Quiz
8%
1 1 1
8%
1 1 *
50%
1 * *
8%
* * *
0%
* 1 1
0%
* * 1
25%
See solution
👍1
What will this code do?
import numpy as np
a = np.array([1, 2, 3])
n1 = round(np.linalg.norm(a, ord=np.inf), 1)
n2 = round(np.linalg.norm(a, ord=1), 1)
n3 = round(np.linalg.norm(a, ord=2), 1)
print(n1, n2, n3)
👍1
Choose your answer
Anonymous Quiz
23%
3.0 6.0 3.7
32%
3.0 3.7 6.0
9%
3.7 6.0 3.0
0%
3.7 1.0 3.0
36%
See solution
👍1
What will this code do?
class D:
__slots__ = ["a", "__dict__"]
def __init__(self):
self.b = 2
d = D()
d.a = 1
d.c = 3
print(sorted(d.__dict__.values()))
Choose your answer
Anonymous Quiz
40%
[1, 2, 3]
8%
[1, 2]
24%
[2, 3]
8%
[1, 3]
4%
[1]
0%
[2]
12%
AttributeError
4%
See solution
👍1🤔1
What will this code do?
g = (str(i**2) for i in range(1, 4))
print("".join(g) + "".join(g))