Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Specification: Using Python3 write a script that defines these 4 functions list_average list_minimum list_maximum above_average list_average This functions must have the following header def list_average(number_list):

Specification:

Using Python3 write a script that defines these 4 functions

list_average

list_minimum

list_maximum

above_average

list_average

This functions must have the following header

def list_average(number_list):

This function should compute the average of the numbers in the last and return that number rounded to the nearest whole number.

list_minimum

This functions must have the following header

def list_minimum(number_list):

This function should loop through the list and find the smallest number in the list. You should assume that no number in the list is greater than 100. Use the following algorithm

set a variable to hold the current minimum value to the highest possible value for each entry in the list if the entry is smaller than the current minimum set the current minimum to the entry

list_maximum

This functions must have the following header

def list_maximum(number_list):

This function should loop through the list and find the largest number in the list. You should assume that no number in the list is less than 0. Use an algorithm similar to the one above.

above_average

This functions must have the following header

def above_average(number_list):

This function should call list_average to compute the average and count the number of entries that are greater than that average.

Suggestions

Create the script file and make it executable. Run the script. It should produce no output. Fix any errors you find.

Create a function header for each of the four functions. For the body of each function write pass. Copy the test code to the bottom of your script. Run the script and fix any errors you find.

Remove the pass statement in list_average. Set the variable total to 0. Write a for loop that loops through the parameter. Inside the loop, add the value each number to total. Return total. Run the script and fix any errors you find.

Using the value of total and the length of the parameter (it is a list), change the return statement so it returns the average of the numbers in the list. Run the script and fix any errors you find.

Modify the return statement so it does not return a decimal. Run the script and fix any errors you find.

Remove the pass statement in list_minimum. Set the variable minimum to 100. Return minimum. Run the script and fix any errors you find.

Just before the return statement in list_minimum write a for loop for every value in the parameter. Inside the loop write an if statement that checks whether the value of each number is less than minimum. If the number is less, set minimum to this new value. Run the script and fix any errors you find.

Remove the pass statement in list_maximum. Set the variable maximum to 0. Return maximum. Run the script and fix any errors you find.

Just before the return statement in list_maximum write a for loop for every value in the parameter. Inside the loop write an if statement that checks whether the value of each number is greater than maximum. If the number is less, set minimum to this new value. Run the script and fix any errors you find.

Remove the pass statement in above_average. Call the function list_average using the parameter as the argument, and store the returned value in the variable average. Return average. Run the script and fix any errors you find.

Before the return statement in above_average set the variable above_count to 0. Return the value of above_count. Run the script and fix any errors you find.

Just before the return statement in above_average write a for loop for every value in the parameter. Inside the loop write an if statement that checks whether the value of each number is greater than average. If it is, increment above_count. Run the script and fix any errors you find.

Test Code

At the bottom of the script you must have the following code

numbers = [62, 60, 58, 50, 85, 93, 99, 77, 72, 74, 61, 68, 73, 65, 57] print("numbers :", numbers) print("average :", list_average(numbers)) print("minimum :", list_minimum(numbers)) print("maximum :", list_maximum(numbers)) print("above average:", above_average(numbers))

Testing:

When you run the script, your output should look like this

numbers : [62, 60, 58, 50, 85, 93, 99, 77, 72, 74, 61, 68, 73, 65, 57] average : 70 minimum : 50 maximum : 99 above average: 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago