Warm-up for those who know how to Python

Hello! We love quizzes on programming languages. 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.


Winners and prize-winners of the quiz

Winner


Vadem


Prize winners


Second place: acerikfy
Third place: Histiophryne
Fourth - tenth place: Swezy_ua , SlonPC , noth , IIRoadRunnerII , term1nal , alexchromets , Tihon_V .


Bonus


So many participants gave the correct answers that we decided to randomly play five more pairs of socks among them. Cool socks from Avito get: sunman , grt_pretender , Vash , ipatov_dn , institoris


Recording a draw




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.


image


Questions


* In all cases we are talking about Python 3.


Question 1


What is the result of the variable t :


 >>> t = (1, 2, [30,40]) >>> t[2] += [50, 60] 

Variants of answers:



Correct answer

TypeError will TypeError , t will be (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:



Correct answer

both of the above are working


Question 3


There is a script:


 class A: def get_some(self): super().get_some() class B: def get_some(self): print('Some') class C(A, B): def get_some(self): super().get_some() c = C() c.get_some() 

What will be the output?


Variants of answers:



Correct answer

Some


Question 4


What will be displayed when running such a code:


 class A: def foo(self): print('foo A') class B: def foo(self): print('foo B') class C(A, B): def foo(self): super().foo() class D(B, A): def foo(self): super().foo() class E(C, D): pass e = E() e.foo() 

Answer Options



Correct answer

TypeError: Cannot create a consistent method resolution order (MRO) for bases A, B


Question 5


Imagine you have a module foo.py:


 def bar(): 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:


 def bar(): print(', !') 

Then you press "input" in foo.py, so that it continues to work and see ...


Variants of answers:



Correct answer

, !


Question 6


What will be displayed when running such a code:


 class A: def __init__(self): print('__init__ A', end=' ') class B: def __init__(self): print('__init__ B', end=' ') class C(A, B): pass c = C() 

Variants of answers:



Correct answer

__init__ A


Question 7


What will be in the output after executing the following code?


 def not_(value): return not value result = not_(0), all(any([not_(x) for x in range(b)]) for b in range(10)) print(result) 

Variants of answers:



Correct answer

(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 Habr's personal after quiz ends.

Source: https://habr.com/ru/post/415913/


All Articles