Write a function called median which takes a list of numbers x and returns the median...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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!") 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!")
Expert Answer:
Answer rating: 100% (QA)
Here is the implementation of the median function def medianx xsort length lenx if length 2 ... View the full answer
Related Book For
Management Accounting Information for Decision-Making and Strategy Execution
ISBN: 978-0137024971
6th Edition
Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young
Posted Date:
Students also viewed these programming questions
-
A particular mathematics textbook measures 8.5 inches by 11 inches by 1.5 inches. How many of these textbooks can be placed into a shipping box that measures 12 inches by 12 inches by 6 inches? How...
-
They are planning to take on Canada again - they will have to play better. What do we call this type of growth?
-
is a branch of computer science that focuses on creating computer systems or computer-controlled machines that have an ability to perform tasks usually associated with human intelligence. Natural...
-
Starting with acetylene as your only source of carbon atoms, identify how you would prepare each member of the following homologous series of aldehydes: a. Ethanal b. Propanal c. Butanal d. Pentanal
-
The comparative balance sheet of Jackson Educational Supply at December 31, 2018, reported the following: Jackson's transactions during 2018 included the following: Requirements 1. Prepare the...
-
In Problem the graph of the function g is formed by applying the indicated sequence of transformations to the given function f. Find an equation for the function g and graph g using 5 x 5 and 5 y...
-
Question: Whitfield, who was black, worked for Ohio Edison. Edison fired him, but then later offered to rehire him. Another employee argued that Edison's original termination of Whitfield had been...
-
Entries for Held-to-Maturity Securities on January 1, 2009, Roosevelt Company purchased 12% bonds, having a maturity value of $500,000, for $537,907.40. The bonds provide the bondholders with a 10%...
-
i need help 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13.. You have chosen biology as your college major because you would like to be a medical doctor. However, you ?nd that the probability of ...
-
All Mopped Up Company has journalized the adjusting entries for the period ending December 31, 2018, and posted the adjustments to the following T-accounts. (Click the icon to view the T-accounts.)...
-
Define the principal criteria that might be used for locating each of the following facilities: hospital chemical factory fire station coffee shop regional automobile parts
-
Consider the compression of a spring by placing a large mass on it. The degree to which the spring compresses is related to its spring constant, k. The force exerted by the spring on the mass is...
-
Nominal variable: Record everyones eye color and create a frequency table, a pie chart, and a one-variable bar chart to display the information. Numerical variable: Each person provides information...
-
A \([0 / 90]_{\mathrm{S}}\) laminate is subjected to a single bending moment per unit length, \(M_{x}\). If the laminate is unconstrained, so that bending along both the \(x\) and the \(y\)...
-
For each variable, suggest ways of collecting data so that the data are at the nominal, ordinal, interval-ratio (numerical), and dichotomous/binary levels of measurement. Note any situations that...
-
Identify some conceptual variables that present interesting challenges to operationalization and discuss them. Pair off, and, in each pair, develop a hypothesis that links your two variables in a...
-
Hope Corp. Reported an EBITDA of P8,000,000 and Net Income of P4,200,000. Interest expense paid for the year amount to P500,000. Corporate tax rate is 30%. Outstanding shares issued and outstanding -...
-
Find the equations of the ellipses satisfying the given conditions. The center of each is at the origin. Passes through (2, 2) and (1, 4)
-
1. Provide several examples of cost objects. 2. Calla Manufacturing Company has 40 machines in its factory. The machines run for two shifts each day, with 30 workers per shift. Allowing for machine...
-
Forecasting resource capacity using a time-driven ABC system Refer to the time-driven ABC analysis of forecasting resource capacity for the Madison Dairy ice cream plant example on pages 181??184 of...
-
Cost rates for peak- and nonpeak-hour capacity usage XZ Discount Brokerage is trying to determine the cost of supplying computing resources in order to determine how much to charge for trades. The...
-
Laws and penalties for driving under the infl uence (DUI) are extremely strict in many states. Furthermore, the number of motor vehicle accidents involving young drivers has increased and become more...
-
Actuaries determine the costs and risks involved with insuring peoples property. Actuaries are experts in evaluating the like lihood of future events. They design creative ways to reduce the...
-
Comparative financial statements for the Rahul Corporation for the year ended December 31 are given below. A total of 500,000 shares of stock were outstanding. The market value of the company's stock...
Study smarter with the SolutionInn App