Knowee
Questions
Features
Study Tools

ou are given a list marks that has the marks scored by a class of students in a Mathematics test. Find the median marks and store it in a float variable named median. You can assume that marks is a list of float values.Procedure to find the median(1) Sort the marks in ascending order. Do not try to use built-in methods. Look at the lecture 4.5 of week-4 to get a better idea.(2) If the number of students is odd, then the median is the middle value in the sorted sequence. If the number of students is even, then the median is the arithmetic mean of the two middle values in the sorted sequence.You do not have to accept input from the console as it has already been provided to you. You do not have to print the output to the console. Input-Output is the responsibility of the autograder for this problem. Refer to PPA-11 if you are not sure how this works.FILL THE MISSING CODEdef solution(marks):    ### Enter your solution below this line    ### Indent your entire code by one unit (4 spaces) to the right    # FILL THE MISSING CODE (...)    sorted_marks = [ ]    while marks != [ ]:        min_mark = ...        for mark in marks:            if mark < min_mark:                ...        marks.remove(min_mark)        ...    n = len(sorted_marks)    if n % 2 != 0:        median = ...    else:        median = ...    ### Enter your solution above this line    return medianSample Test CasesDownload All Test Case 1InputExpected OutputActual Output30,50,40,10,2030.0Test Case 2InputExpected OutputActual Output60,10,30,40,20,5035.0

Question

ou are given a list marks that has the marks scored by a class of students in a Mathematics test. Find the median marks and store it in a float variable named median. You can assume that marks is a list of float values.Procedure to find the median(1) Sort the marks in ascending order. Do not try to use built-in methods. Look at the lecture 4.5 of week-4 to get a better idea.(2) If the number of students is odd, then the median is the middle value in the sorted sequence. If the number of students is even, then the median is the arithmetic mean of the two middle values in the sorted sequence.You do not have to accept input from the console as it has already been provided to you. You do not have to print the output to the console. Input-Output is the responsibility of the autograder for this problem. Refer to PPA-11 if you are not sure how this works.FILL THE MISSING CODEdef solution(marks):    ### Enter your solution below this line    ### Indent your entire code by one unit (4 spaces) to the right    # FILL THE MISSING CODE (...)    sorted_marks = [ ]    while marks != [ ]:        min_mark = ...        for mark in marks:            if mark < min_mark:                ...        marks.remove(min_mark)        ...    n = len(sorted_marks)    if n % 2 != 0:        median = ...    else:        median = ...    ### Enter your solution above this line    return medianSample Test CasesDownload All Test Case 1InputExpected OutputActual Output30,50,40,10,2030.0Test Case 2InputExpected OutputActual Output60,10,30,40,20,5035.0

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the Python code to find the median of the marks:

def solution(marks):
    sorted_marks = []
    while marks != []:
        min_mark = min(marks)
        for mark in marks:
            if mark < min_mark:
                min_mark = mark
        marks.remove(min_mark)
        sorted_marks.append(min_mark)
    n = len(sorted_marks)
    if n % 2 != 0:
        median = sorted_marks[n//2]
    else:
        median = (sorted_marks[n//2 - 1] + sorted_marks[n//2]) / 2
    return median

This code first sorts the marks in ascending order by repeatedly finding the minimum mark and removing it from the original list. Then it calculates the median based on whether the number of marks is odd or even. If it's odd, the median is the middle value in the sorted list. If it's even, the median is the average of the two middle values.

This problem has been solved

Similar Questions

The median of the following data is: Marks: 0-10, 10-20, 20-30, 30-40, 40-50, 50-60, 60-70 No. of Students: 15, 25, 52, 56, 78, 80, 70a.40.67b.45.13c.47.41d.49.28

The median is the middle number in a sorted set of data. If there are an even number of data points, the median is the average of the two middle numbers.Group of answer choicesTrueFalse

Find the median of the following set of scores; 8, 9, 6, 5, I0*1 pointA. 9

Find the median of the following scores:$$

n a sample of six scores on a written assignment, sorted from lowest to highest, the 2nd score is 6, the 3rd score is 7, the 4th score is 8 and the 5th score is 9. The median score in this sample would be: 6.5 7.5 7 I cannot answer this question on the basis of the information given

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.