Exercise 9.1

Start with some file-processing exercises that illustrate the following.

Exercise 9.2

Compare and contrast the following file-reading code segments.

with open('scores.txt') as f:
    for line in f:
        print(line.strip(), end=' ')

f = open('scores.txt')
lines = f.readlines()
for line in lines:
    print(line.strip(), end=' ')

Exercise 9.3

Assuming that f refers to the file shown here and has just been opened, what does skip() return?

Songs Chosen
#Game names for the songs
#All ridiculously good soundtracks
Sep 17, Chrono Cross
Sep 19, Zelda 3
def skip(f):
    line = f.readline()
    line = f.readline()
    while line.startswith('#' ):
        line = f.readline()
    return f.readline()

Exercise 9.4

Using a file that lists a set of movies from the IMDB, “imdb.txt”, compute and print the number of titles that have the word “Moon” or the word “Sun” in them. Assume that each line in the file has just the movie title.