Files, Exceptions, and Modules Python practice problems
Reading and writing text data, handling predictable failures, imports, and safe input boundaries.
Core concepts
Problem-solving patterns
- text file · statistics
- csv · module
- logs · filtering
- replace · text processing
- try except · ZeroDivisionError
What this topic builds
Learn the idea once, use it across the exercises, and explain why your approach works.
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #133Count lines, words, and characters: Analyze a two-line noteStarterPremium
Compute basic statistics for text that could have been read from a file.
- #134Count lines, words, and characters: Blank line countsStarterPremium
Treat a blank line as a line and include the joining newline characters.
- #135Total values from CSV rows: Small order CSVStarterPremium
Calculate the total value of three CSV order rows.
- #136Total values from CSV rows: Decimal unit pricesStarterPremium
Keep currency precision across several decimal prices.
- #137Extract error log entries: Mixed application logBeginnerPremium
Extract only ERROR records from a mixed log.
- #138Extract error log entries: No errorsBeginnerPremium
Report a zero count when the log contains only informational records.
- #139Replace a word in text: Update a configuration noteBeginnerPremium
Replace every old environment name in a line.
- #140Replace a word in text: No matching wordBeginnerPremium
Leave text unchanged and report zero replacements when the target is absent.
- #141Divide safely with exceptions: Valid divisionBeginnerPremium
Safely divide two valid numeric inputs.
- #142Divide safely with exceptions: Zero denominatorBeginnerPremium
Return a helpful message instead of crashing on division by zero.
- #143Validate integer input: Accept signed integerBeginnerPremium
Accept a valid signed integer from a form field.
- #144Validate integer input: Reject decimal textIntermediatePremium
Reject a decimal string when the field specifically requires an integer.
- #145Parse key-value configuration: Application settingsIntermediatePremium
Parse and alphabetize a small configuration block.
- #146Parse key-value configuration: Value contains equalsIntermediatePremium
Keep later equals signs as part of the configuration value.
- #147Summarize JSON orders: Two JSON ordersIntermediatePremium
Summarize quantity and value from an API-style JSON response.
- #148Summarize JSON orders: Empty responseIntermediatePremium
Return zero totals for an empty JSON array.
- #149Calculate days between dates: Project durationIntermediatePremium
Find the number of days between project start and finish dates.
- #150Calculate days between dates: Cross a leap dayAdvancedPremium
Let the datetime module handle February 29 correctly.
- #151Count file extensions: Mixed project filesAdvancedPremium
Count extensions in a small project folder listing.
- #152Count file extensions: Case and extensionless filesAdvancedPremium
Combine extension case and label a file that has no suffix.