June 2019
Beginner to intermediate
770 pages
19h 24m
English
We'll extend our application by adding the analysis feature. As we're using the Command design pattern, we can add yet another subclass for analysis.
Here's our analysis feature, also designed as a subclass of the Command class:
class Analyze_Command(Command): def run(self) -> None: with Path(self.config["outputfile"]).open() as target: rdr = csv.reader(target) outcomes = (float(row[10]) for row in rdr) first = next(outcomes) sum_0, sum_1 = 1, first value_min = value_max = first for value in outcomes: sum_0 += 1 # value**0 sum_1 += value # value**1 value_min = min(value_min, value) value_max = max(value_max, value) mean = sum_1 / sum_0 print( f"{self.config['outputfile']}\n" f"Mean = {mean:.1f}\n" f"House ...
Read now
Unlock full access