Exercises
If you manually close the file by calling .close(), the file may not be closed in exceptional circumstances. Always use the with statement when opening files in Python. See prelab9 for more detail.
Exercise 2.1 (word_count.py).
Write a program that takes in a filename and string as input. Then print how many times that string appears inside the chosen file. If the file does not exist, continue asking for a filename until one is given that exists. Use your source code file as test input.
Make sure to test files with that contain the same word multiple times.
Exercise 2.2 (design, simplediff.py).
Before attempting to code this problem, create a file design that contains some analysis of how you think the problem will be solved. Examples include but are not limited to: a flowchart of events in the program, pseudocode, or a step-by-step process written in plain English. If you choose to scan your design, please make sure that it is legible.
Write a “diff” program that prints out the differences, line by line, of two files. Your program should ask the user for the names of two files, then print the differences between them. Follow the format output as shown below. Make sure to use proper error handling techniques for file I/O.
Assume all files have the same number of lines. The following output shows the output of the files file1.txt and file2.txt.
Exercise 2.3 (readscores.py).
Download the file actsat.txt provided on Canvas. It contains the following columns of whitespace-separated data:
Column 1 2-letter state/territory code (includes DC) Column 2 % of graduates in that state taking the ACT Column 3 Average composite ACT score
Column 4 % of graduates in that state taking the SAT Column 5 Average SAT Math score
Column 6 Average SAT Reading score Column 7 Average SAT Writing score
You must open this file and generate a list of dictionaries containing each row of data. Please use these keys for the dictionaries:
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of