From 0969ab34e656ca044745d73a76642a8d9613b72e Mon Sep 17 00:00:00 2001 From: standenboy Date: Wed, 24 Jan 2024 13:33:00 +0000 Subject: added homework --- comp/hw/111/students.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 comp/hw/111/students.py (limited to 'comp/hw') diff --git a/comp/hw/111/students.py b/comp/hw/111/students.py new file mode 100755 index 0000000..6d9aa13 --- /dev/null +++ b/comp/hw/111/students.py @@ -0,0 +1,48 @@ +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(): + print(''' + 90+ 2 + 80+ 4 + 70+ 2 + 50+ 0 + <50 0 + ''') + +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(calculate_mean("charlie")) +print(top_student()) +grade_spread() +print(improvement("alice")) -- cgit v1.2.3