📑 Task
1)2)
📑 Answer
1)2)
📑 Task
1) What will be the result of running the code?📑 Answer
1) [28.0, 66.0]📑 Task
1) What object does this specific function modify and📑 Answer
1) The function changes the global variable with📑 Task
1) Describe the properties of the created custom dictionary📑 Answer
1) - **Key-Value Mapping**:📑 Task
1) What element removing is fundamentally different from📑 Answer
1) Deleting "11" is different from all others, since such a key📑 Task
1) What does this program calculate?📑 Answer
1) This program calculates the maximum number of pairs of the same letters📑 Task
1) What is the name of the special type of functions📑 Answer
1) This is a coroutine function📑 Task
1) What values do the generators calculate in this case?📑 Answer
1) The outputs: [21, 'a', 21] and [2, 1, 1, 0, 0, 1, 2, 2, 1]📑 Task
1) What value will "population" be after running the code?📑 Answer
1) It will be zero again📑 Task
1) Will the code throw an error due to📑 Answer
1) No, this function provides for filling missing values📑 Task
1) Can you explain difference between the follow objects:📑 Answer
1) a) x_same and x contain from the same elements,📑 Task
1) Will the functions count1() and count2() count events independently of each other?📑 Answer
1) Yes, the functions will count independently of each other📑 Task
1) Find a mistake in the process of recursion the function📑 Answer
1) Incorrect recursion logic: if the list becomes longer by one element,📑 Task
1) Will the result of printing the values for the functions f1 and f2📑 Answer
1) When printed in a loop, the functions' values will be equal📑 Task
1) Can you describe the goals of creating this type of objects?📑 Answer
1) This Neuron class aims to provide a foundation for understanding how📑 Task
1) How will using this decorator affect the function?📑 Answer
1) This gives the function different behavior depending on the type of its argument📑 Task
1) Explain the sequence of actions of this program📑 Answer
1) This code renders the countdown timer in the output area
import time
from datetime import datetime
def timer(maxiter=100):
for i in range(maxiter):
time.sleep(1)
print(f"🕒 {(59 - datetime.now().second):0>2}",
flush=True, end='')
print("\r", flush=True, end='')
timer()
📑 Task
1) What is the decorator used for in the second function definition?
import functools, time
def fibonacci1(n):
if n < 2: return n
return fibonacci1(n - 1) + fibonacci1(n - 2)
# a least-recently-used (LRU) cache eviction policy
@functools.lru_cache(maxsize=None)
def fibonacci2(n):
if n < 2: return n
return fibonacci2(n - 1) + fibonacci2(n - 2)
code_str = lambda f, n: f"""
start = time.time(); {f(n)}; stop = time.time()
print(f'{f}: {{stop - start: e}}')"""
for f in [fibonacci1, fibonacci2]:
exec(code_str(f, 30))
📑 Answer
1) The memoization provided by `functools.lru_cache` prevents redundant calculations
def cache(func):
@functools.wraps(func)
def wrapper_cache(*args, **kwargs):
cache_key = args + tuple(kwargs.items())
if cache_key not in wrapper_cache.cache:
wrapper_cache.cache[cache_key] = func(*args, **kwargs)
return wrapper_cache.cache[cache_key]
wrapper_cache.cache = dict()
return wrapper_cache
@cache
def fibonacci3(n):
if n < 2: return n
return fibonacci3(n - 1) + fibonacci3(n - 2)
for f in [fibonacci1, fibonacci2, fibonacci3]:
exec(code_str(f, 30))
📑 Task
1) What will be the result of running the program?📑 Answer
1) Outputs: {0, '♗', '♙', 1, 2, 3, '♕', '♔', 4, '♖', '♘'} ♘ and False📑 Task
1) Which built-in function will select from the list [a, b]📑 Answer
1) max(a, b)📑 Task
1) The 'id' attribute is directly accessible and modifiable by the user📑 Answer
1) They are named 'read-write attributes' very often📑 Task
1) Describe the object stored in variable c1📑 Answer
1) The object stored in the variable c1 is an instance of the Circle class📑 Task
1) What effect for the built-in function will we see after running this code?📑 Answer
1) The decorated print function now prints each argument📑 Task
1) What actions will this program perform?📑 Answer
1) The program generates a number (-1, 0 or 1) using a special Python module📑 Task
1) How will the second row printed by the program differ from the 1st and 3rd?📑 Answer
1) In the 2nd line the linked list is printed in reverse order📑 Task
1) What will the program print in the last line?📑 Answer
1) ['♗', '♘', '♙', '♔', '♕', '♖', '♗', '♘', '♙', '♔']📑 Task
1) Will the program print three separate lists of elements of different types📑 Answer
1) No📑 Task
1) What will the program print?📑 Answer
1) [] (Ellipsis,) {} {None}, 2, 3, 1📑 Task
1) What will the program print on the first and last lines?📑 Answer
1) 0 0 2 2 0 2 0 0 - the first line📑 Task
1) These programs divide a set into two subsets so📑 Answer
1) The main principle behind these programs is dynamic programming.📑 Task
1) This program divides a set into two subsets so📑 Answer
1) The last line will be [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1]📑 Task
1) What type of function is this?📑 Answer
1) This is a recursive generator📑 Task
1) What will the program print in the last 2 lines?📑 Answer
1) 1 [0, 1, 1, 1] and 0 [0, 1, 1, 1]📑 Task
1) What does the program do?📑 Answer
1) This program generates x (a list of 10 random integers between 0 and 9) and📑 Task
1) What will the program print?📑 Answer
1) 111 121 131 141 151 161 171 181 191📑 Task
1) What result will the program produce?📑 Answer
1) The program will return the number 3 by counting📑 Task
1) What will the program print?
x1 = [[]]
x2 = x1
x1 *= 2
d1 = {1: x1}
d2 = {1: x2}
print(x1, x2)
print(d1, d2)
x1[0].append(2)
print(x1, x2)
print(d1, d2)
d2[1] += [[3]]
print(x1, x2)
print(d1, d2)
📑 Answer
1) Changes to copies and originals will affect each other
x1 = 1
x2 = x1
x1 *= 2
d1 = {1: x1}
d2 = {1: x2}
print(x1, x2)
print(d1, d2)
x1 += 2
print(x1, x2)
print(d1, d2)
d2[1] += 3
print(x1, x2)
print(d1, d2)
📑 Task
1) Describe this function is short (only main characteristics)📑 Answer
1) The function base_power calculates the result📑 Task
1) What result will be printed?📑 Answer
1) [1, 3, 5, 2, 4, 6] [[1, 3, 5], [2, 4, 6]]📑 Task
1) What result will this program produce?📑 Answer
1) True📑 Task
1) What is the last number the program will print?📑 Answer
1) 34📑 Task
1) What will the program print for each case?📑 Answer
1) x0=1 x1=2 x2=4 True and y0=1 y1=2 y2=4 False📑 Task
1) What object is created by the first line of the program?📑 Answer
1) The result is a function that creates a dictionary of functions📑 Task
1) What will the program print?📑 Answer
1) 2 lists of empty lists: [[], [], []] [[], [], []]📑 Task
1) Will the code print two identical lines?📑 Answer
1) The lines will be different:📑 Task
1) What properties of the “_” character do we observe in code cells?📑 Answer
1) "_" is a special variable that represents the last returned value📑 Task
1) What will the program print?📑 Answer
1) Two rows: True and ({'a': 1, 'b': 2}, {'b': 3})📑 Task
1) What two numbers will the program print?📑 Answer
1) 10 29📑 Task
1) What will be printed📑 Answer
1) 1📑 Task
1) What will be the result of the calculations?📑 Answer
1) $polynomials(1, 1, 1)(0)$ builds the function $f(x) = x^2 + x + 1$📑 Task
1) Will the code print out the elements of the interval?📑 Answer
1) The code will only display the command text📑 Task
1) What will the program print?📑 Answer
1) [0, 1, 2] abc - elements of a nested list with indexes 1 and 0📑 Task
1) What will be the result of launching the program?📑 Answer
1) a0b1c📑 Task
1) What will be the result of executing the code?📑 Answer
1) vector() vector(x1=1) vector(x1=1, x2=2)📑 Task
1) What will be the result of the calculation?📑 Answer
1) The built-in function isinstance(x, int) classifies the values True and False📑 Task
1) What objects does the program create?📑 Answer
1) The program creates a list of lambda functions