07. Comprehensive example

A working example of that touches every topic so far.

We have covered quite a bit. Let’s go through an example from problem statement to implementation to test using what we’ve learned so far.

Class recording

Setup

  1. Create a new project directory named comp-example/ or something similar. Open that directory using PyCharm as usual.

  2. Download each of the sample input files below and place them in the project directory:

Problem Description

We’ll start with this high-level description of the problem:

You are tasked with writing a program that can read in a text file where each line has the name of a species of bird. Your program needs to count the number of times each species appears. An example of the input is below. Ask the user to type in the name of the file they wish to be processed.

White-eared Hummingbird
Townsend's Solitaire
Townsend's Solitaire
Yellow-fronted Canary
Chestnut-fronted Macaw

Your program must handle any text file in this format.

Implementation

We’ll start by doing the simplest thing that meets the requirements of the problem description.

Writing pytest code

Finally time to test. When you write test cases and assertions, you are checking the actual computed result against the expected result for a given input.

Last modified September 23, 2025.