Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# 6 ) median def median ( numbers ) : if not numbers: return None # Return None for an empty list sorted _ numbers
# 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
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 median function.
Given argument:
Expected result:
Actual result:
Ran tests in s
FAILED failures
based on the feedback rewrite the code for median without using in built functons like len max min etc
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