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.

    Winners and prize-winners of the quiz



    Prize winners

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


    Так много участников дали правильные ответы, что мы решили разыграть случайным образом еще пять пар носков среди них. Крутые носки от Авито получают: sunman, grt_pretender, Vash, ipatov_dn, institoris

    Запись розыгрыша


    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.



    * 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 TypeErrorin twill (1, 2, [30, 40, 50, 60]),
    • fly TypeErrorin twill (1, 2, [30, 40]),
    • (1, 2, [30, 40, 50, 60]),
    • (1, 2, [30, 40]).

    Correct answer

    вылетит TypeError, в t будет (1, 2, [30, 40, 50, 60])

    Question 2

    Do you have the following structure of modules:


    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.

    Correct answer

    оба варианта выше — работающие

    Question 3

    There is a script:

    classC(A, B):defget_some(self):
    c = C()

    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).

    Correct answer


    Question 4

    What will be displayed when running such a code:

           print('foo A')
           print('foo B')
    classC(A, B):deffoo(self):
    classD(B, A):deffoo(self):
    classE(C, D):pass
    e = E()

    Answer Options

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

    Correct answer

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

    Question 5

    Imagine you have a module foo.py:

        print(‘Привет, друг!’)

    And you run another script:

    import importlib
    import foo
    from foo import bar
    input(‘Друг, нажми ввод’)

    While he is waiting for input, you are changing the foo.py module:

        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).

    Correct answer

    Привет, друг!

    Question 6

    What will be displayed when running such a code:

           print('__init__ A', end=' ')
           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

    Correct answer

    __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))

    Variants of answers:

    • (True, True),
    • (True, False),
    • ValueError: need more than 2 values to unpack,
    • defnot_(value):return value
      SyntaxError: invalid syntax

    Correct answer

    (True, False)


    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.

    Also popular now: