What will this code do?
def f(x):
try:
print('1', end=" ")
y = 1 * 0 if x % 2 else 1 / 0
except:
y = 0
print('2', end=" ")
else:
print('3', end=" ")
finally:
print('4', end=" ")
return y
print(f(1) + f(2))
Choose your answer
Anonymous Quiz
3%
1 2 4 1 3 4 0
39%
1 3 4 1 2 4 0
11%
1 2 4 1 3 4
3%
1 2 4 0
3%
1 3 4 0
22%
Error
19%
See solution
What will this code do?
class A:
def __init__(self, x=0):
self.x = x
def f(self):
print(self.x)
a = A(2020)
f = a.f
print(f.__self__ is a, end=" ")
print(f.__func__ is f, end=" ")
print(f.__func__ is a.f, end=" ")
print(f.__func__ is A.f, end=" ")
👍1
What will this code do?
import numpy as np
print(np.asarray([100, 200, 300]).astype(np.int8))
Choose your answer
Anonymous Quiz
11%
[100 -56 44]
3%
[100 56 -44]
11%
[100 200 -44]
41%
[100 200 300]
8%
[-28 56 44]
11%
[100 72 84]
16%
See solution
🤯2
What will this code do?
import numpy as np
mat = np.array([[1, 2], [4, 5]])
print(round((mat @ np.linalg.inv(mat)).sum()))
Choose the right option for "callables"
class A:
def __init__(self, x):
self.x = x
def __call__(self):
return self.x
class B:
def __init__(self, x):
self.x = x
def method(self):
return self.x
class C:
def __init__(self, x=3):
self.x = x
def __repr__(self):
return str(self.x)
a = A(1)
b = B(2)
c = C(3)
callables = # your code
print([act() for act in callables])
#Output [1, 2, 3]
Choose your answer
Anonymous Quiz
4%
[a, b, C]
19%
[A, B, C]
46%
[a, b.method, C]
0%
[a.__init__, b.method, C]
8%
[a, b, C.__repr__]
4%
TypeError
19%
See solution
👍5
What will this code do?
import numpy as np
A = np.arange(9).reshape(-1, 3)
print(np.linalg.det(A))
👍2
What design pattern is used in this code?
class A: pass
class B: pass
def f(cls, *args):
return cls(*args)
a = f(A)
b = f(B)
Choose your answer
Anonymous Quiz
16%
Decorator
32%
Factory
14%
Module
14%
Facade
9%
Singleton
16%
See solution
👍3
👍2
What needs to be added for the output to be True?
from abc import ABC
class L(ABC): pass
# your code
print(issubclass(tuple, L))
Choose your answer
Anonymous Quiz
19%
L.add(tuple)
9%
L += tuple
9%
L.include(tuple)
19%
L.register(tuple)
16%
L.inherit(tuple)
3%
L.extend(tuple)
25%
See solution