SD 212 Spring 2026 / Homeworks


hw13: Midshipman email addresses

  • Due before the beginning of class on Friday, February 27

Your task

Write a Python program emails.py which does the following:

  • Displays a prompt filename: and gets the user to type in the name of a file on the command line
  • Opens that file an searches for the email addresses of all current USNA Midshipmen in the file. (Current means classes 2026-29.)
  • Prints out the email addresses (only) of all current USNA Midshipmen in the file.

You will want to use the re module for regular expressions, and the functions we learned about in class. Here is the Python re module documentation).

Sample run

If you do a git pull, you should see a new folder for this HW, with a sample file msg.txt for testing.

Here is how your program should work with that file (blue text is what your program should print, green text is what someone would type in):

roche@ubuntu$ python3 emails.py
filename: msg.txt
m283481@usna.edu
m267855@usna.edu
m291234@usna.edu
m290417@usna.edu
m284427@usna.edu
m276745@usna.edu
m263227@usna.edu

Submit command

To submit files for this homework, run one of these commands:

submit -c=sd212 -p=hw13 emails.py
club -csd212 -phw13 emails.py