Answered step by step
Verified Expert Solution
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.
# Questions and Results
SURVEYQUESTION "How many hours of sleep do you get on average?"
SURVEYRESULTS
SURVEYQUESTION "How many cups of coffee do you drink per day?"
SURVEYRESULTS
# count
def countnumbers:
result
for in numbers:
result
return result
# summate
def summatenumbers:
result
for num in numbers:
result num
return result
# mean
def meannumbers:
if not numbers:
return None
total, count
for num in numbers:
total num
count
return roundtotal count,
# maximum
def maximumnumbers:
if not numbers:
return None
result numbers
for num in numbers:
if num result:
result num
return result
# minimum
def minimumnumbers:
if not numbers:
return None
result numbers
for num in numbers:
if num result:
result num
return result
# median
def mediannumbers:
if not numbers:
return None # Return None for an empty list
sortednumbers sortednumbers
midindex
for in sortednumbers:
midindex
midindex
count
for in sortednumbers:
count
if midindex count:
return roundsortednumbersmidindex sortednumbersmidindex
else:
return roundsortednumbersmidindex
# square
def squarenumbers:
result
for num in numbers:
result.appendnum
return result
# standarddeviation
def standarddeviationnumbers:
if countnumbers:
return None
sumvalues, sumsquaredvalues
for num in numbers:
sumvalues num
sumsquaredvalues num
n countnumbers
stdev sumsquaredvalues sumvalues nn
return roundstdev
# Additional code for survey questions and results
SURVEYQUESTION "How many hours of exercise do you do per week?"
SURVEYRESULTS
if namemain:
printWe asked", countSURVEYRESULTS "people the following question."
printSURVEYQUESTION
printHere are the statistical results:"
printtCount: countSURVEYRESULTS
printtSummate: summateSURVEYRESULTS
printtMean: meanSURVEYRESULTS
printtMedian: medianSURVEYRESULTS
printtMaximum: maximumSURVEYRESULTS
printtMinimum: minimumSURVEYRESULTS
printtSquare: squareSURVEYRESULTS
printtStandard Deviation:", standarddeviationSURVEYRESULTS
print
We asked", countSURVEYRESULTS "people the following question."
printSURVEYQUESTION
printHere are the statistical results:"
printtCount: countSURVEYRESULTS
printtSummate: summateSURVEYRESULTS
printtMean: meanSURVEYRESULTS
printtMedian: medianSURVEYRESULTS
printtMaximum: maximumSURVEYRESULTS
printtMinimum: minimumSURVEYRESULTS
printtSquare: squareSURVEYRESULTS
printtStandard Deviation:", standarddeviationSURVEYRESULTS
print
We asked", countSURVEYRESULTS "people the following question."
printSURVEYQUESTION
printHere are the statistical results:"
printtCount: countSURVEYRESULTS
printtSummate: summateSURVEYRESULTS
printtMean: meanSURVEYRESULTS
printtMedian: medianSURVEYRESULTS
printtMaximum: maximumSURVEYRESULTS
printtMinimum: minimumSURVEYRESULTS
printtSquare: squareSURVEYRESULTS
printtStandard Deviation:", standarddeviationSURVEYRESULTS
Run testmysolution.py
F
FAIL: testmedian mainTestComponents
median
Traceback most recent call last:
File UserssonachhetryDownloadscswpsurveystatstestmysolution.py line in testmedian
self.genericteststudentmain.median
File UserssonachhetryDownloadscswpsurveystatstestmysolution.py line in generictest
self.wrongresultargs expectedresult, actualresult
File UserssonachhetryDownloadscswpsurveystatstestmysolution.py line in wrongresult
self.assertAlmostEqualexpected actual, placesTOLERANCE, msgmsg
AssertionError: within places difference :
Incorrect value returned for media
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started