Python & ML tasks
416 subscribers
2 photos
3 links
Python, functions, classes, iterators, generators, numpy, pandas, scikit-learn, TensorFlow
for advertising: @dina_ladnyuk

For advertising and donations in USD:
SWIFTBIC BUKBGB22
IBAN GB40 BUKB 2047 3453 2396 99
Mrs Dina Ladnyuk
Download Telegram
What this code do?
class A:
__x = 1
def f(self):
return "f from A"

def g(self):
return "g from A"

class B:
__x = 2
def f(self):
return "f from B"

def g(self):
return "g from B"

class C(A, B):
f = B.f

c = C()
print(c.f(), c.g(), c._A__x, c._B__x)
What this code do?
def intersect(*seqs):
if len(seqs) > 2:
return intersect(seqs[0], intersect(*seqs[1:]))
seq1, seq2 = seqs[0], seqs[1]
res = []
for x in seq1:
if x in seq2:
res.append(x)
return res

x = intersect([1, 2, "a", "b"], (1, 4, "b"), {1, "b", "c"})
print(x)
What this code do?
def f(n):
return 0 if n == 0 else 2**n + f(n-1)
print(f(3))
Select the correct option
Anonymous Quiz
12%
0
0%
8
18%
12
18%
13
53%
14
0%
16
0%
Show results
What this code do?
def f():
x = 1
y = 1
def g():
nonlocal x
x, y = 2, 2
g()
print(x, y)

f()
Choose the correct answer
Anonymous Quiz
0%
1 1
11%
1 2
61%
2 1
17%
2 2
6%
NameError
6%
Show results
Given code:
try:
my_x = 1
raise Exception('exception') #1
except Exception as my_err:
print(my_err) #2
my_y = 2
print(my_x) #3
print(my_y) #4
print(my_err) #5
Which of the lines in this code will cause an unintercepted exception:
Anonymous Quiz
15%
1
23%
2
15%
3
15%
4
31%
5
What will this code do?
x = 1
def f1():
return x
def f2():
global x
x = 2
return x
def f3():
global x
return x
print(f1(), f2(), f3(), f1())
Two modules are given testmod.py and runmod.py
#testmod.py
x = 0
def f1():
x = 10
def f2():
global x
x += 1
def f3():
import testmod
testmod.x += 1
def f4():
import sys
sys.modules["testmod"].x += 1

#runmod.py
import testmod as t
t.f1();t.f2();t.f3();t.f4()
print(t.x)
The entry point into the program is a module runmod.py. What will be the conclusion?
Anonymous Quiz
0%
0
11%
1
22%
2
44%
3
11%
10
11%
11
0%
12
0%
13
0%
See solution
What will this code do?
def maker(n):
s = 0
def g(x=n):
nonlocal s
s += x
return s
return lambda x: s + x + g()
f = maker(2)
print(f(3), f(3))android
Choose the correct answer
Anonymous Quiz
8%
3 5
33%
5 5
17%
7 7
17%
5 7
25%
5 9
0%
7 9
0%
9 9
What will this code do?
f = lambda x, f=lambda x: x**2: f(x)
print(f(5), f(5, f))
What will this code do?
def maker(n, h=lambda: 3):
return lambda f=h: f()**n, lambda f=h: n**f()
f, g = maker(2)
r = f(g) + g(f)
print(r)
1