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
-
(a) All electrons with initial kinetic energy 32eV encounter a square barrier with height 41eV and width 0.2S nm. What is the probability that the electron will tunnel through the barrier? (b) A...
-
Student researchers Adam, Edward, and Kian wondered if music would affect performance for certain tasks. To find out, they had student volunteers sort a shuffled set of 26 playing cards by face value...
-
Analyze the tube-flow reactor data in Table B. 6 using all possible regressions. Evaluate the subset models using the \(R_{p}^{2}, C_{p}\), and \(M S_{\text {Res }}\) criteria. Justify your choice of...
-
In December 2010, Ultravision established its predetermined overhead rate for movies produced during year 2011 by using the following cost predictions: overhead costs, $1,800,000, and direct labor...
-
What role do ethical considerations play in crisis management decision-making processes, particularly concerning stakeholder prioritization and resource allocation during tumultuous circumstances ?
-
Hooyay is a low cost manufacturer of smartphones in Myanmar. They recently listed in 2017 on the Singapore Exchange and did not issue any dividends for 2017 and have no plans to for 2018. They do...
-
The pH active salt hydrolysis reaction for NH4NO3 is: O NH4+ (aq) + NO3(aq) NH4NO3(aq) O NH4+ (aq) + HO(l) H3O*(aq) + NH3(aq) NO3(aq) + 3 HO(l) HNO3(aq) + 2 H3O+ (aq) O NH4+ (aq) + HO(l) NH3(aq) +...
-
Dale owns an excavating business and has a large piece of heavy machinery in which his bank has a perfected security interest. Strapped for cash, Dale takes out a loan with EZ cash, using the same...
-
Suppose that you're a Small Business Account Manager at BMO. Your customers, Pirre and Belle Chen, owners of C'Est Bon Authentic Chinese Cuisine*, wish to upgrade their restaurant's technology at a...
-
Select all that apply Select the following statements that are correct regarding Dividends? (Check all that apply.) Multiple select question. Dividends are closed into retained earnings by debiting...
-
The lecture presented both Pugh's method and weighted objectives as options to show a "systematic qualitative screening process". Provide one advantage and one disadvantage to using either of these...
-
Does the public get a say when setting up performance-based budgeting? Are people even aware when budget are being put together
-
Explain in detail about c.t. and p.t.?
-
Determine the center and radius of each circle. Sketch each circle. 4x 2 + 4y 2 9 = 16y
-
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...
-
Consider the following observations: a. Fit the nonlinear regression model \[ y=\theta_{1} e^{\theta_{2} x}+\varepsilon \] to these data. Discuss how you obtained the starting values. b. Test for...
-
For the models shown below, determine whether it is a linear model, an intrinsically linear model, or a nonlinear model. If the model is intrinsically linear, show how it can be linearized by a...
-
Sketch the expectation function for the logistic growth model (12.34) for \(\theta_{1}=1, \theta_{3}=1\), and values of \(\theta_{2}=1,4,8\), respectively. Overlay these plots on the same \(x-y\)...
Study smarter with the SolutionInn App