in pythonThis program requires two functions. In the main function:create an empty list.use a loop to add twelve random integers, each in the range 1 to 50 inclusive, to your list. Duplicates are okay.sort the list in descending order.use slice syntax to create a sub-list of the largest three integers.create another sub-list slice holding the smallest three integers.print both of the above sub-lists. Crude "dumps" that display [ ] and commas are okay.call a custom, void function named show_list that takes your entire list as an argument. In the show_list function:use a loop to display all twelve integers on one line separated by a single space.report the total of all integers in the list.Sample OutputThe largest three integers are [44, 41, 38]The smallest three integers are [18, 12, 1]Here are all of the integers, sorted highest to lowest...44 41 38 37 37 34 25 21 21 18 12 1The sum of all integers in the list is 329

Question
8 views

in python

This program requires two functions. In the main function:

• create an empty list.
• use a loop to add twelve random integers, each in the range 1 to 50 inclusive, to your list. Duplicates are okay.
• sort the list in descending order.
• use slice syntax to create a sub-list of the largest three integers.
• create another sub-list slice holding the smallest three integers.
• print both of the above sub-lists. Crude "dumps" that display [ ] and commas are okay.
• call a custom, void function named show_list that takes your entire list as an argument.

In the show_list function:

• use a loop to display all twelve integers on one line separated by a single space.
• report the total of all integers in the list.

Sample Output
The largest three integers are [44, 41, 38]
The smallest three integers are [18, 12, 1]
Here are all of the integers, sorted highest to lowest...
44 41 38 37 37 34 25 21 21 18 12 1
The sum of all integers in the list is 329

check_circle

Step 1

Programming instructions:

• First, make a list with no values.
• Then, utilize for-loop to add values in the list using random.randint().
• After that, sort the list in descending order using List_Name.sort(reverse=True).
• Now, to print three largest integers, just print the first three values of the list as they are sorted in descending order utilizing List_Name[:3].
• To print three smallest integers, just print the last three values of the list as they are sorted in descending order utilizing List_Name[-3:].
• Call the show_list function which takes an argument of the list. In this function, print all the values of the list and then, print the sum of these values using sum(List_Name) function.
Step 2

Complete program:

import random

# Print the integers in the list separated by " "

def show_list(lst):

for value in lst:

print(value, end = ' ')

print()

# Print the sum of all integers in the list

print('Sum of integers in the list: ', sum(lst))

def main():

# Make an empty list

lst = []

# Use loop to create random number and add to list

for i in range(12):

lst.append(random.randint(1, 50))

# Sort the list in descending ...

Want to see the full answer?

See Solution

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in