Created
December 9, 2024 17:03
-
-
Save dersavage/ecb25a340b8796606a598b026893f82c to your computer and use it in GitHub Desktop.
Mooc.fi official solution for end of Part 4 project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def exam_and_exercise_completed(inpt): | |
space = inpt.find(" ") | |
exam = int(inpt[:space]) | |
exercise = int(inpt[space+1:]) | |
return [exam, exercise] | |
def exercise_points(amount): | |
return amount // 10 | |
def grade(points): | |
boundary = [0, 15, 18, 21, 24, 28] | |
for i in range(5, -1, -1): | |
if points >= boundary[i]: | |
return i | |
def mean(points): | |
return sum(points) / len(points) | |
def main(): | |
points = [] | |
grades = [0] * 6 | |
while True: | |
inpt = input("Exam points and exercises completed: ") | |
if len(inpt) == 0: | |
break | |
exam_and_exercises = exam_and_exercise_completed(inpt) | |
exercise_pnts = exercise_points(exam_and_exercises[1]) | |
total_points = exam_and_exercises[0] + exercise_pnts | |
points.append(total_points) | |
grd = grade(total_points) | |
if exam_and_exercises[0] < 10: | |
grd = 0 | |
grades[grd] += 1 | |
pass_pros = 100 * (len(points) - grades[0]) / len(points) | |
print("Statistics:") | |
print(f"Points average: {mean(points):.1f}") | |
print(f"Pass percentage: {pass_pros:.1f}") | |
print("Grade distribution:") | |
for i in range(5, -1, -1): | |
stars = "*" * grades[i] | |
print(f" {i}: {stars}") | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment