Problem set#

Get second last#

problem_set.get_second_last(nums: list[float]) float#

Get the 2nd last element of the list after some modifications.

Parameters:

nums (list of float) – A list containing at least 3 real numbers.

Returns:

The second-to-last element after being increased by the average of the list, raised to the power of 2, and rounded to 2 decimal places.

Return type:

float

Examples

>>> get_second_last([1.2, 3.4, 5.6, 7.8, 9.0])
174.24

Note

  • Average = (1.2+3.4+5.6+7.8+9.0)/5 = 5.4

  • 2nd last = 7.8

  • (7.8 + 5.4) = 13.2

  • 13.2 ** 2 = 174.24

  • round to 2 decimal places = 174.24

Get first three reversed#

problem_set.get_first_three_reversed(nums: list[float]) list[float]#

Return the first three elements of the list in reverse order.

Parameters:

nums (list of float) – A list containing at least 3 real numbers.

Returns:

A new list containing the first three elements of nums, in reverse order.

Return type:

list of float

Examples

>>> get_first_three_reversed([10.0, 20.0, 30.0, 40.0, 50.0])
[30.0, 20.0, 10.0]

Note

  • Start: [10.0, 20.0, 30.0, 40.0, 50.0]

  • Take the first three elements: [10.0, 20.0, 30.0]

  • Reverse those elements: [30.0, 20.0, 10.0]

Modify list#

problem_set.modify_list(my_list: list) list#

Modify a list of elements by applying multiple list operations in sequence.

Parameters:

my_list (list) – A list containing at least five elements.

Returns:

The updated list after the following modifications: - Remove the last element of the list. - Insert the string “hello” at index 2. - Extend the list by adding two new elements: “lemon” and “strawberry” at the end. - Remove the element at index 4. - Insert the number 99 at the beginning of the list (index 0).

Return type:

list

Examples

>>> modify_list([1, 2, 3, 4, 5, 6])
[99, 1, 2, 'hello', 3, 5, 'lemon', 'strawberry']

Note

  • Start: [1, 2, 3, 4, 5, 6]

  • Remove last element (6): [1, 2, 3, 4, 5]

  • Insert “hello” at index 2: [1, 2, ‘hello’, 3, 4, 5]

  • Extend with [“lemon”, “strawberry”]: [1, 2, ‘hello’, 3, 4, 5, ‘lemon’, ‘strawberry’]

  • Remove element at index 4 (element 4): [1, 2, ‘hello’, 3, 5, ‘lemon’, ‘strawberry’]

  • Insert 99 at beginning: [99, 1, 2, ‘hello’, 3, 5, ‘lemon’, ‘strawberry’]

Access 3D array#

problem_set.access_3d_elements(array_3d: list) list#

Access specific elements from a 3D array.

Parameters:

array_3d (list) – A 3-dimensional array.

Returns:

  • Index 0: The first 2D array.

  • Index 1: The last row of the first 2D array.

  • Index 2: The last element in the the first row of the last 2D array.

Return type:

list

Examples

>>> access_3d_elements([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
[[[1, 2, 3],[4, 5, 6]], [4, 5, 6], 9]

Note

  • The first 2D array: [[1, 2, 3],[4, 5, 6]]

  • The last row of the first 2D array: [4, 5, 6]

  • The last element in the the first row of the last 2D array: 9

Calculate the area of trapezoid#

problem_set.calc_area_of_trapezoid(a: int, b: int, h: int) float#

Calculate the area of trapezoid.

Parameters:
  • a (int) – Length of base 1.

  • b (int) – Length of base 2.

  • h (int) – Height of trapezoid.

Returns:

The area of trapezoid.

Return type:

float

Examples

>>> calc_area_of_trapezoid(8, 16, 12)
144.0

Note

  • Area = ((8 + 16) / 2) * 12 = 144.0