What will this code do?
class A:
count = 0
@classmethod
def inc(cls):
cls.count += 1
def __init__ (self):
self.inc()
class B(A):
count = 0
def __init__(self):
A.__init__(self)
class C(A):
count = 0
x = A()
y1, y2 = B(), B()
z1, z2, z3 = C(), C(), C()
print(x.count, y1.count, z1.count)
Choose your answer
Anonymous Quiz
17%
(1, 2, 3)
8%
(1, 3, 7)
17%
(1, 3, 0)
8%
(1, 2, 0)
17%
(1, 0, 0)
25%
(1, 3, 3)
8%
See solution
What will this code do?
import random
random.random() < random.randint(1, 10)
Choose your answer
Anonymous Quiz
67%
True
4%
False
4%
AttributeError
4%
TypeError
13%
Undefined
8%
See solution
What will this code do?
class counter:
def __init__(self, func):
self.calls = 0
self.func = func
def __call__(self, *args):
self.calls += 1
return self.func(*args), self.calls
@counter
def square(a):
return a ** 2
print(square(2)[0] + square(3)[0] + square(4)[1])
What will this code do?
class A: pass
class B:
def __init__(self):
x = super()
print(x is A, x is B)
b = B()
Choose your answer
Anonymous Quiz
29%
True True
7%
True False
50%
False True
14%
False False
0%
See solution
What will this code do?
def f(*, name):
print(len(name), end=" ")
try:
f(name="vasya")
f("sergey")
except:
f(name="oleg")
Choose your answer
Anonymous Quiz
6%
4
25%
5 6
6%
5 6 4
0%
6 4
38%
5 4
25%
TypeError
0%
See solution
What will this code do?
def f(x, y):
return x ** y
print(f.__call__(3, 2) + f(2, 3))
Choose your answer
Anonymous Quiz
10%
8
0%
9
5%
10
5%
16
62%
17
0%
27
10%
AttributeError
10%
See solution
Choose your answer
Anonymous Quiz
7%
'1110'
14%
'11o10'
7%
'110o10'
29%
'0b110o10'
0%
'0o1011'
14%
'110b1000'
7%
'30o10'
21%
See solution