Someone Help Please Help Would Greatly Appreciated Question Requires Calculate Values Usin Q43835439
can someone help me please, any help would be greatlyappreciated
This question requires you to calculate values using Pythonfunctions. There are two approaches you can use.
- add suitable code to the provided file, then run it
- run the provided file first, to load the required function anddata into memory, then do the calculation in the interactive Pythonshell.
Feel free to choose the approach you prefer.
Open the files and inspect the contents of q5.py. The Pythonlist college in q5.py holds 46 yearly values for the number ofmillions of public college enrolments in the USA (Statista 2019a).The Python list oil in q5.py holds 46 yearly values for a.q5.pyimports the Python function median() you used to calculate themedian of a list of numbers.
Use this function to find the medianof the list college.
In your Solution document give themedian, correct to two decimal places. Also provide the Python codeyou used for calling the median() function and explain how youexecuted it.
(4 marks)
(here is the Q5code)
“””
from stats import median
from stats import mean
from tma02_stats import corr_coef
“”” You can use one of two approaches
— add suitable code below and then run thisfile
— run this file first then do the calculationin the Python
interactive shell.
“””
“””
U.S. college enrollment statistics for public colleges from 1971 to2016 (in millions).
“””
college = [6.8, 7.07, 7.42, 7.99, 8.83, 8.65, 8.85, 8.79, 9.04,9.46, 9.65, 9.7, 9.68, 9.48, 9.48, 9.71, 9.97, 10.16, 10.58, 10.84,11.31, 11.38, 11.19, 11.13, 11.09, 11.13, 11.2, 11.14, 11.38,11.75, 12.23, 12.75, 12.86, 12.98, 13.02, 13.18, 13.49, 13.97,14.81, 15.14, 15.12, 14.88, 14.75, 14.65, 14.57, 14.56]
“””
Average annual price of a barrel of oil in US dollars from 1971 -2016.
“””
oil = [1.7, 1.82, 2.7, 11.0, 10.43, 11.6, 12.5, 12.79, 29.19,35.52, 34.0, 32.38, 29.04, 28.2
****************************this is the statscode***********************************
import math
def median(alist):
“”” Calculates the median of a list ofnumbers.
The list must not be empty.
“””
number_of_values = len(alist)
sorted_list = sorted(alist)
# Two cases, depending on whether the numberof values is odd or even.
quotient = number_of_values // 2
remainder = number_of_values % 2
if (remainder == 1):
result =sorted_list[quotient]
else:
result =(sorted_list[quotient – 1] + sorted_list[quotient]) / 2
return result
def test_median():
assert median([2]) == 2
assert median([4, 3]) == 3.5
assert median([3, 1, 8, 4, 7, 6, 4, 2, 5, 9]) ==4.5
assert median([7, 2, 6, 2, 5, 3, 1, 0, 8, 6, 6,4, 9]) == 5
# Unit test
test_median()
def mean(list):
“””Return mean of list”””
sum = 0
count = 0
for item in list:
sum = sum + item
count = count + 1
return sum / count
def test_mean():
list = [1, 2, 3, 4, 5]
assert(mean(list) == 3)
# Unit test
test_mean()
def corr_coef(list_x, list_y):
“”” Return correlation between values in list_xand list_y.
Lists must be of equal length.
“””
x_bar = mean(list_x)
y_bar = mean(list_y)
sxy = 0
sxx = 0
syy = 0
for index in range(len(list_x)):
x = list_x[index]
y = list_y[index]
sxy = sxy + (x – x_bar)* (y – y_bar)
sxx = sxx + (x – x_bar)* (x – x_bar)
syy = syy + (y – y_bar)* (y – y_bar)
return sxy / math.sqrt(sxx * syy)
def test_corr_coef():
# Data from M140 Unit 9 Example 5
list1 = [78.9, 75.8, 77.3, 74.2, 78.1, 72.8,77.6, 77.9]
list2 = [56.7, 53.1, 56.1, 55.9, 54.1, 48.6,59.4, 54.0]
assert round(corr_coef(list1, list2), 2) ==0.64
# Unit test
test_corr_coef()
Expert Answer
Answer to can someone help me please, any help would be greatly appreciated This question requires you to calculate values using P…
OR