Question: Write a function that takes a list as an argument and returns a tuple with the mean and median ( mean will be the first

Write a function that takes a list as an argument and returns a tuple with the mean and median (mean will be the first element of the tuple). If no elements are in the list return None for both elements of the tuple. Do not use built-in or imported functions except len and round or the sort method for lists.
To find the mean (arithmetic average), we find the sum of the elements in the list divided by the length of the list.
To find the median, we sort the list and find the value of the middle element. If the length of the list is even, we need to find the average of the two middle elements.
Hint for median: Sort the list. To find the middle index for a list of odd length, we can divide the length by 2 and truncate the result. There is an operator that can do this all at once. To find the middle indices for a list of even length, we need the index at the length divided by 2 and the index right before it.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!