Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# Author name: Sona Chhetry # I have neither given nor received unauthorized assistance on # this assignment. I did not fabricate the answers to

# Author name: Sona Chhetry
# I have neither given nor received unauthorized assistance on
# this assignment. I did not fabricate the answers to my
# survey questions.
# 0) Questions and Results
SURVEY_QUESTION_1= "How many hours of sleep do you get on average?"
SURVEY_RESULTS_1=[7,8,5,6,7,7,6,8,7,5]
SURVEY_QUESTION_2= "How many cups of coffee do you drink per day?"
SURVEY_RESULTS_2=[2,3,1,2,3,2,1,3,2,2]
# 1) count
def count(numbers):
result =0
for _ in numbers:
result +=1
return result
# 2) summate
def summate(numbers):
result =0
for num in numbers:
result += num
return result
# 3) mean
def mean(numbers):
if not numbers:
return None
total, count =0,0
for num in numbers:
total += num
count +=1
return round(total / count, 2)
# 4) maximum
def maximum(numbers):
if not numbers:
return None
result = numbers[0]
for num in numbers:
if num > result:
result = num
return result
# 5) minimum
def minimum(numbers):
if not numbers:
return None
result = numbers[0]
for num in numbers:
if num < result:
result = num
return result
# 6) median
def median(numbers):
if not numbers:
return None # Return None for an empty list
sorted_numbers = sorted(numbers)
mid_index =0
for _ in sorted_numbers:
mid_index +=1
mid_index //=2
count =0
for _ in sorted_numbers:
count +=1
if mid_index *2== count:
return round((sorted_numbers[mid_index -1]+ sorted_numbers[mid_index])/2,2)
else:
return round(sorted_numbers[mid_index],2)
# 7) square
def square(numbers):
result =[]
for num in numbers:
result.append(num **2)
return result
# 8) standard_deviation
def standard_deviation(numbers):
if count(numbers)<2:
return None
sum_values, sum_squared_values =0,0
for num in numbers:
sum_values += num
sum_squared_values += num **2
n = count(numbers)
stdev =((sum_squared_values -(sum_values **2)/ n)/(n -1))**0.5
return round(stdev,2)
# Additional code for survey questions and results
SURVEY_QUESTION = "How many hours of exercise do you do per week?"
SURVEY_RESULTS =[3,4,2,5,3,4,3,2,4,5]
if __name__=="__main__":
print("We asked", count(SURVEY_RESULTS_1), "people the following question.")
print('"'+SURVEY_QUESTION_1+'"')
print("Here are the statistical results:")
print("\tCount:", count(SURVEY_RESULTS_1))
print("\tSummate:", summate(SURVEY_RESULTS_1))
print("\tMean:", mean(SURVEY_RESULTS_1))
print("\tMedian:", median(SURVEY_RESULTS_1))
print("\tMaximum:", maximum(SURVEY_RESULTS_1))
print("\tMinimum:", minimum(SURVEY_RESULTS_1))
print("\tSquare:", square(SURVEY_RESULTS_1))
print("\tStandard Deviation:", standard_deviation(SURVEY_RESULTS_1))
print("
We asked", count(SURVEY_RESULTS_2), "people the following question.")
print('"'+SURVEY_QUESTION_2+'"')
print("Here are the statistical results:")
print("\tCount:", count(SURVEY_RESULTS_2))
print("\tSummate:", summate(SURVEY_RESULTS_2))
print("\tMean:", mean(SURVEY_RESULTS_2))
print("\tMedian:", median(SURVEY_RESULTS_2))
print("\tMaximum:", maximum(SURVEY_RESULTS_2))
print("\tMinimum:", minimum(SURVEY_RESULTS_2))
print("\tSquare:", square(SURVEY_RESULTS_2))
print("\tStandard Deviation:", standard_deviation(SURVEY_RESULTS_2))
print("
We asked", count(SURVEY_RESULTS), "people the following question.")
print('"'+SURVEY_QUESTION+'"')
print("Here are the statistical results:")
print("\tCount:", count(SURVEY_RESULTS))
print("\tSummate:", summate(SURVEY_RESULTS))
print("\tMean:", mean(SURVEY_RESULTS))
print("\tMedian:", median(SURVEY_RESULTS))
print("\tMaximum:", maximum(SURVEY_RESULTS))
print("\tMinimum:", minimum(SURVEY_RESULTS))
print("\tSquare:", square(SURVEY_RESULTS))
print("\tStandard Deviation:", standard_deviation(SURVEY_RESULTS))
>>>%Run test_my_solution.py
...F......
======================================================================
FAIL: test_median (__main__.TestComponents)
median
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/sonachhetry/Downloads/cs1064-w22-p3-survey_stats/test_my_solution.py", line 202, in test_median
self.generic_test(student_main.median)
File "/Users/sonachhetry/Downloads/cs1064-w22-p3-survey_stats/test_my_solution.py", line 172, in generic_test
self.wrong_result(args, expected_result, actual_result)
File "/Users/sonachhetry/Downloads/cs1064-w22-p3-survey_stats/test_my_solution.py", line 167, in wrong_result
self.assertAlmostEqual(expected, actual, places=TOLERANCE, msg=msg)
AssertionError: 1!=0.0 within 2 places (1.0 difference) :
Incorrect value returned for `media

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

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

Identify four applications of HRM to healthcare organizations.

Answered: 1 week ago