What will this code do?
class A:
def __iter__(self):
yield from range(10)
a = A()
print(5 in a, 20 in a)
What will this code do?
def g(f1, f2, x):
return f1(x) + f2(x) if x else 0
f1, f2 = lambda x: x**3/abs(x), lambda x: x % 2
x = 121
g(f1, f2, -x) + g(f1, f2, x)
What will this code do?
import re
sent = 'Hello, Ben! How are you doing?'
lister = filter(None, re.split("[,!?]+", sent))
print(len(list(lister)))
👍1🤯1
Given code
def f(n):
def g(x):
return x ** n
return g
g = f(3)
print(g(2), g(3))
What is the name of this technique?
Anonymous Quiz
28%
decorator
10%
convolution
8%
carrying
17%
closure
5%
memoization
8%
generation
2%
robustness
2%
binding
20%
See solution
😁1
What is used to evaluate a model in machine learning?
Anonymous Quiz
2%
Source dataset
37%
Training dataset
50%
Test dataset
6%
Nothing, since there is no point in evaluating the model
6%
See solution
😱2
What will this code do?
from itertools import product
a = [1, 2]
b = [3, 4]
sum(sum(product(a, b), (0, 0)))
👍1🤯1
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()))