Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this problem, you will get practice with sorting and slicing lists, and with using list functions such as max ( ) and min ( )
this problem, you will get practice with sorting and slicing lists, and with using list functions such as max and min
Create a code cell and copy the following code into it without the indentations
import random
random.seed
randomlist random.samplerange
This code will create a list named randomlist that contains randomly generated integers. We will discuss how this
code works later in the course.
Print the length of randomlist. Then print the first elements of this list, all on the same line. Format your output as
follows:
Length of randomlist: xxxx
First Elements of randomlist: xxxx
Use the sum function to calculate the sum of the elements in randomlist. Print the result in the format shown below.
Match the formatting exactly, including the period at the end of the sentence. There should be no space between the
sum and the period.
The sum of the elements in random list is xxxx
Create a list named sortedlist that contains the same elements of randomlist, but sorted in increasing order.
The order of the elements in randomlist should not be changed. Print the first ten elements of both lists on separate
lines. Format your output as follows:
First Elements of sortedlist: xxxx
First Elements of randomlist: xxxx
Create lists named botslice, midslice, and topslice as follows:
botslice should contain the smallest elements in sortedlist.
midslice should contain the middle elements in sortedlist.
topslice should contain the largest elements in sortedlist.
Print the six messages shown below, with the appropriate numerical values inserted in place of the xxxx symbols. Include
the periods at the end of the sentences, and include blank lines between each pair of sentences, as shown.
The smallest element of botslice is xxxx
The largest element of botslice is xxxx
The smallest element of midslice is xxxx
The largest element of midslice is xxxx
The smallest element of topslice is xxxx
The largest element of topslice is xxxx
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started