Lecture 16 - Exercises

16A - split and join

  1. What does the following print?

16B - Reading and Writing Files

  1. Suppose the file rick.txt contains:

    Never gonna give you up

    What is the output of the following code?

  2. Assume a file called fin.txt exists in the same directory as the program below, and has the following contents:

    Start: 4pm
    End: 7pm
    3h

    What does the following program print?

Problems

  1. Implement the following function:

  2. Download test.txt. Write a program that counts and prints the number of unique lines in the file. Be sure that the text file and your Python program are saved in the same directory.

  3. Implement the following function:

  4. Download AboutYou.csv. Write a Python program to calculate the average number of quarters at Western among each of three groups of students:

  5. Implement the following function: