What will this code do?
class C:
listing = []
x = C()
x.listing.append(1)
x.listing.append(1)
x.listing = 1
print(x.listing, C.listing)
Choose your answer
Anonymous Quiz
7%
1[1]
0%
[1][1]
60%
1[1,1]
20%
[1,1]1
0%
[1,1][1,1]
13%
See solution
What will this code do?
def f():
setattr(f, "x", getattr(f, "x", 0) + 1)
f.f = f
return f
x = f()()().f.f.f().f.x
print(x)
Choose your answer
Anonymous Quiz
29%
1
0%
2
14%
3
29%
4
0%
5
0%
TypeError
0%
AttributeError
0%
ValueError
29%
See solution
How to access the private attribute __x?
Anonymous Quiz
13%
a.x
35%
a.__x
17%
a.A__x
0%
a.A.__x
17%
a._A__x
0%
a._A.__x
13%
a.__A__x
4%
a.__A.__x
0%
a.__x_A
0%
a.__x._A
What will 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 will 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 your answer
Anonymous Quiz
27%
[1, 2, 4, 'a', 'b', 'c']
0%
[1, 'b', 'c']
36%
[1, 'b']
9%
[1]
18%
([1, 2, 'a', 'b'], [1, 'b'])
9%
IndexError
0%
See solution
What will this code do?
def f(n):
return 0 if n == 0 else 2**n + f(n-1)
print(f(3))
What will this code do?
def f():
x = 1
y = 1
def g():
nonlocal x
x, y = 2, 2
g()
print(x, y)
f()
What will this code do?
x = [1, 2, 3]
y = sorted(x)
y.insert(0, 100)
print(x[0])
Choose your answer
Anonymous Quiz
55%
1
14%
2
5%
3
14%
TypeError
5%
ValueError
9%
IndexError
0%
See solution
Given code
try:
my_x = 1
raise 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
Which of the lines in this code will cause an uncaught exception:
Anonymous Quiz
20%
1
20%
2
30%
3
10%
4
10%
5
10%
See solution