Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python help plz Exercise 5 Write a median function that has a numbers parameter. numbers is a list of numbers. This function returns the statistical

python help plz image text in transcribed
Exercise 5 Write a median function that has a numbers parameter. numbers is a list of numbers. This function returns the statistical median of the numbers list. The median of an odd-length list is the number in the middlemost number when the list is in sorted order. If the list has an even length, the median is the average of the two middlemost numbers when the list is in sorted order. You can use Python's builtin sort() method to sort the numbers list. Passing an empty list to median should cause it to return None. Don't forget to add an appropriate docstring. To test your function try the below assert statements (copy paste them to your code in the main function). assert median ([])== None, "Empty list test failed!" assert median ([1,2,3])==2, "Test 2 failed." assert median ([3,7,10,4,1,9,6,5,2,8])=5.5, "Test 3 failed." assert median ([3,7,10,4,1,9,6,2,8])=6, "Test 4 failed." import randon random. seed(42) testData =[3,7,10,4,1,9,6,2,8] for i in range (1600): random. shuffle(testData) assert median(testData) ==6 print("All tests succesfull!") Exercise 6 Write a closest Average function that has a numbers parameter. numbers is a list of numbers. This function returns the element closest to the average of the numbers list. You can use Python's built-in sum() methodif you wish. Passing an empty list to closest Average should cause it to return None. Don't forget to add an appropriate docstring. To test your function try the below assert statements (copy paste them to your code in the main function). assert closestAverage ([])= None, "Empty list test failed!" assert closestAverage ([1,2,3])==2, "Test 2 failed." assert closestAverage ([3,7,10,4,1,9,5,6,2,8])=5, "Test 3 failed." assert closestAverage ([3,7,10,4,1,9,6,2,8])=6, "Test 4 failed." import random random.seed(42) testData =[3,7,10,4,1,9,6,2,8] for i in range (10e0): random. shuffle(testData) assert closestAverage(testData) ==6 print("All tests succesfull!")

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

What are topics included within employee services?

Answered: 1 week ago

Question

Explain what a system clock is, and why it is important

Answered: 1 week ago

Question

b. Does senior management trust the team?

Answered: 1 week ago

Question

How will the members be held accountable?

Answered: 1 week ago