Access your current level in Python

  • The result of the quiz will determine the level to begin.
  • The Quiz contains 12 questions. All questions are mandatory.
  • You will be able to reattempt the quiz after 6 months.

Access your current level in Python

  1. Consider this bit of Python code:
    Code Editor: num_1 = 10 num_2 = 20 num_3 = num_1 num_1 = 100

    What is the final value stored in num_3?

  2. If you want to increment the value stored in the num_1 variable by 10 which of the following Python statements are valid?

  3. Identify the outcome of the following code:
    class Competition:
    __raise_amount = 1.10
    def __init__(self, name, prize):
    self.__name = name
    self.__prize = prize
    def get_name(self):
    return self. name
    def get_prize(self):
    return self.__prize
    def raiseprize(self):
    self.__prize = self.__prize * self__raise_amount
    race = Competition('Race', 100)
    print(type(race))

  4. What is the result of the following code?
    class Competition:
    def __init__(self, name, prize):
    self.__name = name
    self.__prize = prize
    rowing = Competition('Rowing', 10000)
    print(rowing)

  5. What is the purpose of the following code?
    class LinkedList:
    def __init__(self):
    self.head = None

  6. Review the following code:
    class MethodSub:
    def __init__(self, number):
    self.number = number
    def __sub__(self, other):
    return self.number + other.number
    num_1 = MethodSub(10)
    num_2 = MethodSub(8)
    print(num_1 - num_2)
    What is the output?

  7. Which statement about threads in Python is true?

  8. Consider the following code:
    import time
    import threading
    from pprint import pprint
    def sleeping_func():
    time.sleep(2)
    print(“”nHello from sleeping_fun!“”)
    x = threading.Thread()
    x.start()
    x = threading.Thread(target = sleeping_func)
    x.start()
    pprint(threading.active_count())
    print()
    pprint(threading.enumerate())
    print()
    pprint(threading.current_thread()

    When is the sleeping_func() likely to execute?

  9. Review the following Python test script:
    def test_type():
    assert type(1 + 2) is int
    def test_add_int():
    assert 5 + 2 == 7
    def test_string():
    assert 'u' in 'sun'
    def test_add_string():
    assert ('sunny' + 'day') == 'sunnyday'

    You run pytest from the directory that this script is stored. Which test is executed first?

  10. Review the following code statements and identify the correct statement.
    Code Editor(Python):
    from openpyxl.styles import NamedStyle
    custom_style = NamedStyle(name=“header”)
    custom_style.font = Font(bold=True)
    custom_sytle.border = Border(bottom=Side(border_style=“thin”))
    custom_style.alignment = Alignment(horizontal=“center”, vertical=“center”)

  11. What does AF_INET signify in the given code?
    Code Editor:
    import socket

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:

  12. What is the result of the following code?

    Code Editor(Python):
    import openpyxl
    work_book = openpyxl.Workbook()
    work_book.active

    sheet = work_book['Sheet']
    sheet['A1'] = 'Hello'
    sheet['B1'] = 'Excel'
    sheet['C1'] = 'Users!'