Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function called median which takes a list of numbers x and returns the median value (see Wikipedia:Median). If the length of the

Write a function called median which takes a list of numbers x and returns the median value (see Wikipedia:Median). If the length of the list x is odd then the median is the middle value and if the length is even then the median is the average of the two middle values. For example, the median of [1,3,-1,6,2] is 2 and the median of [1,3,2,6,-1,0] is 1.5. Use the built-in function sorted to sort the list of values. Use the modulo operator % to determine if an integer is odd or even. This is an exercise in pure Python. Do not use any Python packages such as math or numpy or scipy for this exercise. def median(x): |]: "Check median returns the correct datatype. (1 mark)" assert isinstance (median ([1,2,3,4]), float) print("Problem 1 Test 1: Success!") ]: "Check median returns the correct values. This cell contains hidden tests. (2 marks)" assert abs (median ([1.0, 2.0,3.0]) 2.0) < 1e-14 print("Problem 1 Test 2: Success!") - ]: "Check median returns the correct values. This cell contains hidden tests. (2 marks)" assert abs(median([1.0,2.0,3.0, 4.0]) 2.5) < 1e-14 print("Problem 1 Test 3: Success!")

Step by Step Solution

3.50 Rating (150 Votes )

There are 3 Steps involved in it

Step: 1

Here is the implementation of the median function def medianx xsort length lenx if length 2 ... 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

Management Accounting Information for Decision-Making and Strategy Execution

Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young

6th Edition

137024975, 978-0137024971

More Books

Students also viewed these Programming questions

Question

Identify the four schedules of reinforcement.

Answered: 1 week ago