Skip to content

Instantly share code, notes, and snippets.

@dersavage
Created December 9, 2024 17:27
Show Gist options
  • Save dersavage/aea5692630c511ffb5776b947c4164e7 to your computer and use it in GitHub Desktop.
Save dersavage/aea5692630c511ffb5776b947c4164e7 to your computer and use it in GitHub Desktop.
Jan's cousin's solution for stats_printer.py
exam_p, exer_p, grade_distribution = [], [], [0] * 6
while True:
incoming_data = input("Exam points and exercises completed): ")
if incoming_data == '':
break
first_num, second_num = map(int, incoming_data.split())
exam_p.append(first_num)
exer_p.append(min(second_num // 10, 10))
total_students = len(exam_p)
pass_count = 0
for i in range(len(exam_p)):
total_score = exam_p[i] + exer_p[i]
if exam_p[i] < 10:
grade_distribution[0] += 1
else:
if 0 <= total_score <= 14:
grade_distribution[0] += 1
elif 15 <= total_score <= 17:
grade_distribution[1] += 1
pass_count += 1
elif 18 <= total_score <= 20:
grade_distribution[2] += 1
pass_count += 1
elif 21 <= total_score <= 23:
grade_distribution[3] += 1
pass_count += 1
elif 24 <= total_score <= 27:
grade_distribution[4] += 1
pass_count += 1
elif 28 <= total_score <= 30:
grade_distribution[5] += 1
pass_count += 1
total_points_sum = sum(exam_p[i] + exer_p[i] for i in range(len(exam_p)))
points_average = total_points_sum / len(exam_p) if exam_p else 0.0
pass_percentage = (pass_count / total_students * 100) if exam_p else 0
print("Statistics:")
print(f"Points average: {points_average:.1f}")
print(f"Pass percentage: {pass_percentage:.1f}")
print("Grade distribution:")
for grade in range(5, -1, -1):
print(f" {grade}: {'*' * grade_distribution[grade]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment