Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2"""Solution to chapter 5, exercise 23: test_scores""" 

3 

4import json 

5import glob 

6 

7 

8def print_scores(dirname): 

9 

10 scores = {} 

11 

12 for filename in glob.glob(f'{dirname}/*.json'): 

13 scores[filename] = {} 

14 

15 with open(filename) as f: 

16 for result in json.load(f): 

17 for subject, score in result.items(): 

18 scores[filename].setdefault(subject, []) 

19 scores[filename][subject].append(score) 

20 

21 for one_class in scores: 

22 print(one_class) 

23 for subject, subject_scores in scores[one_class].items(): 

24 min_score = min(subject_scores) 

25 max_score = max(subject_scores) 

26 average_score = (sum(subject_scores) / 

27 len(subject_scores)) 

28 

29 print( 

30 f'\t{subject}: min {min_score}, max {max_score}, average {average_score}')