What will this code do?
def f(n):
s = 0
for i in range(n):
s += i
s += ~i
return s
print(f(1) + f(10) + f(100))
🤩1
Choose your answer
Anonymous Quiz
5%
-9990
0%
-4995
19%
-111
14%
0
12%
111
12%
4995
10%
9990
29%
See solution
🎉2
👍2
Which of the classes from the scikit-learn library does NOT solve the problem of regression?
Anonymous Quiz
17%
DecisionTreeRegressor
20%
RandomForestRegressor
20%
LinearRegression
37%
LogisticRegression
7%
See solution
👍1
What will this code do?
class MyList(list):
def __getitem__(self, index):
if type(index) is slice:
index = slice(index.start - 1, index.stop - 1, index.step)
elif type(index) is int:
index -= 1
return list.__getitem__(self, index)
l = MyList(["one", "two", "three", "four", "five", "six"])
print(l[1], l[-1], l[0], l[2:4])
What will this code do?
a = 1 * 1
b = 1 / 1
print(a == 1, b == 1, a is 1, b is 1)
How to print python philosophy?
Anonymous Quiz
37%
import this
12%
import philosophy
20%
print(__philosophy__)
6%
print(__pypy__)
4%
print()
8%
exec('__ph__')
14%
See solution
🤯2
What will this code do?
class A:
def __init__(self, x):
self.x = x
def __getattribute__(self, name):
if name == '__add__':
self.x *= 10
return object.__getattribute__(self, name)
def __add__(self, other):
return self.x + other.x
a1 = A(2)
a2 = A(3)
print(a1 + a2, a1.__add__(a2))
👍1
Choose your answer
Anonymous Quiz
22%
5 5
5%
23 5
38%
5 23
14%
23 23
8%
NameError
3%
RecursionError
11%
See solution
🎉1
What will this code do?
S = 'abcdef'
print(S.islower() + S.lower().isalpha() + S.isupper())
Choose your answer
Anonymous Quiz
2%
0
2%
1
41%
2
0%
3
12%
6
2%
True
10%
False
20%
TypeError
10%
See solution
👍1
What will this code do?
class A:
def __getitem__(self, i):
return i
a = A()
a.__getitem__ = lambda i: i**2
print(a[4])
Choose your answer
Anonymous Quiz
9%
4
9%
8
62%
16
2%
None
17%
IndexError
0%
TypeError
2%
See solution
👍1
What will this code do?
from functools import reduce
print(reduce(lambda acc, x: x * acc, [1,2,3,4], 1))
👍1
What will this code do?
class A:
x = 'hello'
def __getitem__(self, i):
return getattr(self.x, '__getitem__')(i) * 2
def __getattr__(self, attr):
return getattr(self.x, attr)
a = A()
print(a[0] + a.upper()[1:])
Choose your answer
Anonymous Quiz
11%
HELLO
29%
hELLO
4%
hhello
36%
hhELLO
7%
HHELLO
7%
IndexError
7%
See solution
👍1