Monday, May 27, 2024

📑 Coroutine Math Functions

📑 Task

1) What is the name of the special type of functions
(the second one in the given code fragment)?
Why do we add "None" to the beginning of the list of angle measurements?
2) Modify this function so that it collects values and does not print them out

📑 Answer

1) This is a coroutine function
We must initialize the coroutine and prepare it to accept values
so we are starting with None
2)

Sunday, May 26, 2024

📑 List Methods and Generators

📑 Task

1) What values do the generators calculate in this case?
What will the program print?
2) Give a similar example using generators and list methods,
where it is impossible to use lists with completely different values

📑 Answer

1) The outputs: [21, 'a', 21] and [2, 1, 1, 0, 0, 1, 2, 2, 1]
Both generators calculate their values in the first list
based on information from the second one
2)

Saturday, May 25, 2024

📑 Applying Class Methods

📑 Task

1) What value will "population" be after running the code?
2) Modify the class code so that its examples can transfer any indicators
to each other (energy, objects collected during the task, etc.)

📑 Answer

1) It will be zero again
2)

Thursday, May 23, 2024

📑 Table Formatting

📑 Task

1) Will the code throw an error due to
different lengths of nested components?
2) Suggest a code snippet that will turn nested lists
into tabs with html markup

📑 Answer

1) No, this function provides for filling missing values
with spaces when printing
2)

Tuesday, May 21, 2024

📑 Object Similarity

📑 Task

1) Can you explain difference between the follow objects:
x_same, x_copy, x_equal?
2) Write a function that compares two lists based on the following parameters:
a) is the list length the same,
b) do all unique elements match,
c) whether the composition of the list as a whole is the same,
d) are the elements arranged in the same order,
e) whether they have the same address in memory.
Apply it to the indicated objects

📑 Answer

1) a) x_same and x contain from the same elements,
but they are different and independent objects
b) x_equal refers to the same list object as x,
so they share the same memory address
c) x_copy refers to a new list object created by making
a shallow copy of x, so x_copy is a different object
with the connection to the original list because of
the nested mutable component []
2)

Sunday, May 19, 2024

📑 Count in Two

📑 Task

1) Will the functions count1() and count2() count events independently of each other?
2) How can we define other Python objects that allow us
to count events in programs using the same rule?
For example, classes or generators

📑 Answer

1) Yes, the functions will count independently of each other
depending on the number of calls
2)

Saturday, May 18, 2024

📑 Max Product of Three

📑 Task

1) Find a mistake in the process of recursion the function
for calculating the maximum product of three numbers in the list
2) Suggest a possible decision to build a recursive function

📑 Answer

1) Incorrect recursion logic: if the list becomes longer by one element,
then all the indices of the elements that give the maximum product
could be changed, not only one index
2)