Warm-up for those who know how to Python
Hello! We adore programming language quizzes. In our blog, we have already posted as many as three: the first is in Python, PHP, Golang, DevOps, the second is completely in Go, the third is only in PHP. Today's quiz is dedicated exclusively to Python.
We invite you to warm up in honor of the end of another summer week and on the eve of PyCon Russia 2018 . (By the way, who is going? We will be there).
Under the cut - seven questions, tips from a friend, Chapaev, excerpts from ABBA ( what? Yes! ) And cool merch.
UPD: We've finished accepting answers. Thanks to everyone who participated! Answers to questions - inside the text, and the winners and runners-up under the spoiler.
Winner
Prize winners
Second place: acerikfy
Third place: Histiophryne
Fourth - tenth place: Swezy_ua , SlonPC , noth , IIRoadRunnerII , term1nal , alexchromets , Tihon_V .
Bonus
Так много участников дали правильные ответы, что мы решили разыграть случайным образом еще пять пар носков среди них. Крутые носки от Авито получают: sunman, grt_pretender, Vash, ipatov_dn, institoris
Запись розыгрыша
Prizes
Prizes are distributed among the top ten. To the first person who correctly answers all the questions of the Python quiz, we’ll send an advanced Avito-merch collection: a sweatshirt, socks and holivary bones - we can guess what backend language and frontend framework your new project will be written. We will award the second participant who has coped with the tasks with holivarny bones, socks and a T-shirt. The third will get the same set, but without a t-shirt / sweatshirt. Among the remaining seven participants we will play a thermal bottle with a carbine, which can be taken even on a hike, even on a hackathon.
Questions
* In all cases we are talking about Python 3.
Question 1
What result will be in a variable t
:
>>> t = (1, 2, [30,40])
>>> t[2] += [50, 60]
Variants of answers:
- fly
TypeError
int
will(1, 2, [30, 40, 50, 60])
, - fly
TypeError
int
will(1, 2, [30, 40])
, (1, 2, [30, 40, 50, 60])
,(1, 2, [30, 40])
.
вылетит TypeError
, в t
будет (1, 2, [30, 40, 50, 60])
Question 2
Do you have the following structure of modules:
foo_app/
snatch/
qwerty.py
bar_app/
snatch/
mamamia.py
How to make it so that in the code you can import these modules in this way:
from snatch import qwerty, mamamia
Variants of answers:
- before running the script to execute
export PYTHONPATH=foo_аpp:bаr_аpp
, - at the top of the script add:
import sys sys.path.extend([‘foo_app’, ‘bar_app’])
- both options above are working,
- so it cannot be done.
оба варианта выше — работающие
Question 3
There is a script:
classA:defget_some(self):
super().get_some()
classB:defget_some(self):
print('Some')
classC(A, B):defget_some(self):
super().get_some()
c = C()
c.get_some()
What will be the output?
Variants of answers:
AttributeError: 'C' object has no attribute 'get_some'
,AttributeError: 'super' object has no attribute 'get_some'
,Some
,- emptiness (without Chapaev).
Some
Question 4
What will be displayed when running such a code:
classA:deffoo(self):
print('foo A')
classB:deffoo(self):
print('foo B')
classC(A, B):deffoo(self):
super().foo()
classD(B, A):deffoo(self):
super().foo()
classE(C, D):pass
e = E()
e.foo()
Answer Options
foo A
,foo B
,TypeError: Cannot create a consistent method resolution order (MRO) for bases A, B
.
TypeError: Cannot create a consistent method resolution order (MRO) for bases A, B
Question 5
Imagine you have a module foo.py:
defbar():
print(‘Привет, друг!’)
And you run another script:
import importlib
import foo
from foo import bar
input(‘Друг, нажми ввод’)
importlib.reload(foo)
bar()
While he is waiting for input, you are changing the foo.py module:
defbar():
print(‘Пока, друг!’)
Then you press “input” in foo.py, so that it continues to work and see ...
Variants of answers:
ModuleReloadedException: method bar() was reloaded
,Пока, друг!
,Привет, друг!
,- emptiness (and again there is no Chapaev).
Привет, друг!
Question 6
What will be displayed when running such a code:
classA:def__init__(self):
print('__init__ A', end=' ')
classB:def__init__(self):
print('__init__ B', end=' ')
classC(A, B):pass
c = C()
Variants of answers:
__init__ A __init__ B
__init__ B __init__ A
__init__ A
__init__ B
__init__ A
Question 7
What will be in the output after executing the following code?
defnot_(value):returnnot value
result = not_(0), all(any([not_(x) for x in range(b)]) for b in range(10))
print(result)
Variants of answers:
(True, True)
,(True, False)
,ValueError: need more than 2 values to unpack
,defnot_(value):return value ^ SyntaxError: invalid syntax
(True, False)
Summarizing
Answers to questions will post an update to the post on Wednesday, July 25th. If you decide - put the answers under the spoiler to make it more interesting for other participants to solve the questions.
And (!) Do not forget to check the personal Habr after the end of the quiz.