Respuesta :
Answer:
- def three_largest_numbers(num_list):
- sort_list = num_list
- sort_list.sort(reverse=True)
- return sort_list[0:3]
- print(three_largest_numbers([5, 7, 1, 8, 9, 3, 6]))
Explanation:
Firstly, we declare a function that will take one input list, num_list (Line 1). To avoid modifying the original num_list, we create a copy of num_list and assign it to a new list, sort_list (Line 2) in the function. Next, we use Python list sort function to sort the list in descending order (Line 3). At last, return the first three elements of the sort_list as output (Line 4).
We test the function using a sample list (Line 6) and we shall get [9, 8, 7] printed in terminal.
The function that takes a single parameter(num_list) and return a new list of the three largest number is as follows:
def three_largest_number(num_list):
x = sorted(num_list, reverse=True)
return x[0:3]
print(three_largest_number([1, 5, 6, 7, 2, 5, 9, 8]))
Code explanation.
The code is written in python.
- A function named "three_largest_number" is defined and it accepts "num_list" as a parameter.
- The x variable is used to store the reverse of the sorted num_list.
- Then, we return the first three value of the reverse sorted num_list.
- The returned value is the three maximum number in the num_list.
- Finally, we call the function with its required parameters.
learn more on python here: https://brainly.com/question/17329431
