Overview

Objective

This homework assignment is intended to get you comfortable using Python, especially file I/O and the data structures and types we've talked about in class. However, I fully expect that you will need some things that we haven't discussed in class for an elegant solution. Read the docs, google, and check Stack Overflow - learn to learn. Make sure you have downloaded War and Peace from the data folder and know its filepath.

Grading

This assignment is worth ten points. You should complete it in this notebook. When complete, you should email the assignment to Dr. Johnson. The due date is Wednesday, June 1, by 9:00AM. Late assignments will be penalized 1 point per day (that's one full letter grade per day late). Submission anytime after 9:00AM on June 1 counts as 1 day late.

Working together

You may discuss and work on this assignment with your peers. However, you must submit your own work, copying is not permitted. You will be graded individually, and if your work appears to be a copy of someone else's, I may ask for you to demonstrate in person and on the spot your ability to write the code to solve a similar problem.

Format

Do all of your work in this notebook. I should be able to change the filepath to war and peace in the first cell block, after which I should be able to restart the kernel and run all cells to see the correct output. I should not need to make any other changes to the file. You should verify that you've done the work correctly by doing this yourself (restart the kernel and run all using the 'kernel' dropdown menu above).

Instructions

  1. Write a function that returns (as an int) the number of lines in the file. (3 points)
  2. Use the function in a print statement to nicely format and print 'War and Peace is ___ lines long'. (1 point)
  3. Write a function that searches through War and Peace for the first occurrence of a character's name. (4 points)
  4. Use the function to find the first occurrences of the following character's names: Dokhturov (last name only), Vasili Kuragin (both names), Langeron (last name only). Nicely format the print statement to report the line on which each character's name occurred. (2 points)
  5. (Bonus): Write a function that counts the number of occurrences of a character's name. How many times does the name Bezukhov occur? (2 points)

In [ ]:
# your code here: