Week 3 assignment 1 redo

mail@pastecode.io avatar
unknown
python
10 months ago
353 B
12
Indexable
    for i in range(len(marks)):
        for j in range(len(marks)):
            if marks[i] > marks[j]:
                marks[i], marks[j] = marks[j], marks[i]

    median = 0
    if len(marks) % 2 != 0:
        median = marks[len(marks) // 2]
    else:
        mid_index = len(marks) // 2
        median = (marks[mid_index] + marks[mid_index - 1]) / 2
Leave a Comment