← Back to File Operations & Error Handling
Module 5
Exercises
Practice what you've learned with hands-on coding exercises
Complete these exercises to reinforce your understanding of File Operations & Error Handling. Try to solve them on your own before checking the solutions!
Exercise 1: File Reader
EasyRead a text file and perform operations: count lines, words, characters, and find specific words.
💡 Hints
- Use 'with open()' context manager
- Read file line by line
- Use string methods for counting
Exercise 2: CSV Data Processor
MediumRead CSV data, filter rows, calculate statistics, and write results to a new CSV file.
💡 Hints
- Import csv module
- Use csv.DictReader for easy access
- Process data row by row
Exercise 3: JSON Configuration Manager
MediumCreate a program that reads, modifies, and saves configuration data in JSON format.
💡 Hints
- Import json module
- Use json.load() and json.dump()
- Handle nested dictionaries
Exercise 4: Error Handler
HardWrite a robust program that handles multiple types of errors gracefully with try-except blocks.
💡 Hints
- Use specific exception types
- Provide helpful error messages
- Use finally for cleanup
Ready to check your work?
View the solutions to see how you did and learn best practices.
View Solutions