summaryrefslogtreecommitdiff
path: root/comp/hw/111/students.py
blob: 3ea8741e7a649ed63432bdb91823405017a139fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
students = [['alice', [75,80,85,90]], ['bob',[60,65,70,75]],['charlie',[90,85,80,78]]]


def calculate_mean(name):
    for i in students:
        if i[0] == name:
            mean = sum(i[1]) / len(i[1])
            return mean
    return "not in list"

def top_student():
    top = 0
    for i in students:
        this_student_mean = calculate_mean(i[0])
        if this_student_mean > top:
            top = this_student_mean
    for i in students:
        if calculate_mean(i[0]) == top:
            return i[0]

def grade_spread():
    prev = 0
    current = 50
    count = 0
    for x in range(6): 
        for i in students:
            for j in i[1]:
                if j <= current:
                    count = count + 1
        print(f"{prev} - {current}: {count}")
        prev = current
        current = current + 10

def improvement(name):
    for i in students:
        if i[0] == name:
            low = i[1][0]
            high = 0
            for i in i[1]:
                if i < low:
                    low = i
                elif i > high:
                    high = i
            range = high - low
            return range
    return "not in list"


print(f"mean for charle: {calculate_mean('charlie')}")
print(f"the top student is: {top_student()}")	
print("the grade spread is")
grade_spread()
print(f"the grade improvement of alice is: {improvement('alice')}")