# quiz.py: code to process quizzes import sys from typing import * class Quiz: """Track data related to a quiz for an entire section (that is, all students who took the quiz).""" def __init__(self, name: str, score_list: List[float]): self._name = name.strip() self._scores = score_list @property def name(self) -> str: return self._name def average(self) -> float: """Average of all non-negative scores.""" nonnegatives = [n for n in self._scores if n > 0] if len(nonnegatives) == 0: return 0.0 else: return sum(nonnegatives) / len(nonnegatives) def read_quiz() -> Quiz: """Read a quiz from standard input where the first line gives the quiz name and the remaining lines give the scores.""" score_list = [] name = '' for line in sys.stdin: if name == '': name = line else: try: num = float(line) except ValueError: break # done with loop! score_list += [num] return Quiz(name, score_list)