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
Asked Oct 7, 2019
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

Expert Answer

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

Check out a sample Q&A here.

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

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: In C++ Create a function called Swap. It should take in two numbers by reference (use the & oper...

A: Note:The following program includes the “swap()” function to swap the two numbers using reference. H...

question_answer

Q: Draw an EER diagram for the following situation using the traditional EER notation. A technology com...

A: EER diagram is stand for enhanced entity relationship diagram. EER is used for designed high- level ...

question_answer

Q: Write a GUI application that calculates a car’s gas mileage. The application should let the user ent...

A: Program plan:Test.javaImport the required header filesDefine “Test” classCreate an object for the “M...

question_answer

Q: 1. /15 points] Consider the following function: Func1(A, n) * A is an array of integers 1 80; 2 for ...

A: a)Worst case running time of Func1:The random number between 1 to “n” is assigned to “k” in the give...

question_answer

Q: In C++ Create an array of random 10 random numbers. Use the "range-based for loop" (sometimes called...

A: Program designuse a reference type loop variable in the range-based for loop to assign elements to a...

question_answer

Q: PLEASE EXPLAIN ALL STEPS: simplify the boolean equations: xz + (xy + ~z) ~xyz + yz + x~y

A: 1)xz + (xy + ~z)For simplifying the Boolean expression, use Karnaugh Map and follow the below steps-...

question_answer

Q: Draw a flowchart for a program that shows the logic for a program that generates a random number.  T...

A: The following program will generate a random number 0 or 1. If the generated random number is 0, the...

question_answer

Q: My C++ program is supposed to check if a string input is in descending order. When I try to run it, ...

A: The given C++ code has few logical errors due to which it is not resulting the correct output. Revis...

question_answer

Q: Is BIOS volatile?

A: Volatile memory is the computer memory that maintains its data only when the computer is in power. A...