What do you need to add to make the code work?
class A:
def __init__(self, x):
self.x = x
def __and__(self, other):
return self.x + other.x
a1 = A(1)
a2 = A(2)
# your code
output: 3
Choose your answer
Anonymous Quiz
36%
print(a1 and a2)
34%
print(a1 & a2)
7%
print(a1 && a2)
9%
print(a1 | a2)
5%
print(a1 ^ a2)
9%
See solution
What will this code do?
def f(n):
x, y = -n, -n
return x is y
print(f(0), f(5), f(10))
What will this code do?
class A:
def __init__(self, value):
self.value = value
def __call__(self, other):
return self.value ** other
x = A(2)
print(x(3))
Choose your answer
Anonymous Quiz
4%
2
6%
3
13%
6
55%
8
1%
None
16%
TypeError: 'A' object is not callable
4%
See solution
What will this code do?
from functools import reduce
funcs = [str.title, lambda x: x*2]
print(reduce(lambda acc, f: f(acc), funcs, 'hello'))
What will this code do?
class A:
def __init__(self, x):
self._x = x
@property
def x(self):
return self._x
a = A(1)
print(A.x.fget(a), a.x)
Choose your answer
Anonymous Quiz
14%
1 None
6%
None 1
34%
1 1
3%
None None
23%
AttributeError
3%
TypeError
0%
ValueError
17%
See solution
Choose your answer
Anonymous Quiz
23%
False False
22%
False True
38%
True False
12%
True True
5%
See solution
What will this code do?
a = 0
def func():
global a
for num in [2, 4, 8]:
a += 1
yield(num * 0.5)
array = []
for val in func():
array.append(int(a == val))
print(sum(array))
👍1
What will this code do?
a = 1; b = 2
print(eval('print(a + b, end=" ") or 0'))
Choose your answer
Anonymous Quiz
7%
0
27%
3
12%
3 None
20%
3 0
0%
None 3
18%
SyntaxError
17%
See solution