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
Which of the following expressions will not return True?
Anonymous Quiz
8%
a.x == 1
17%
a.y == 2
10%
A.x == 1
37%
A.y == 2
8%
a.__dict__['y'] == 2
10%
A.__dict__['x'] == 1
12%
See solution
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