Quiz 8: Files, Exceptions, List Comprehensions, and Sorting
Learning Goals
Students should be able to:
- Open files in different modes using Python's open() function
- Use Python's
with ... as
syntax for opening and closing files. - Read data from files using readline() and readlines()
- Write data to files using write()
- Explain the difference between reading, writing, and appending files
- Understand how programs create and modify files
- Explain what an exception is and give examples of exceptions in Python
-
Handle exceptions using try/except statements
- Use list comprehension expressions to concisely create lists using the mapping and filtering patterns.
- Use
sorted
and.sort
with thekey
andreverse
keyword parameters to sort lists
Study Guide
Note: list comprehensions and sorting will be covered on this week's quiz.
Blank (fill in your solutions)
Solutions
After your quiz is graded by instructors, you will get an email from Gradescope. Solutions for individual quiz questions are provided in the Gradescope rubric.