Files, Text Data, Exceptions, and Modules Python practice problems
Process file-like text safely and use Python's csv, json, datetime, pathlib, and exception tools.
Core concepts
Problem-solving patterns
- Open or parse safely → validate → handle failure → produce result
Reported company tags
All 20 problems in this topic
Work from top to bottom to build the concept gradually.
- #161Count lines, words, and characters: Analyze a two-line noteIntermediatePremium
Compute basic statistics for text that could have been read from a file.
- #162Count lines, words, and characters: Blank line countsIntermediatePremium
Treat a blank line as a line and include the joining newline characters.
- #163Total values from CSV rows: Small order CSVIntermediatePremium
Calculate the total value of three CSV order rows.
- #164Total values from CSV rows: Decimal unit pricesIntermediatePremium
Keep currency precision across several decimal prices.
- #165Extract error log entries: Mixed application logIntermediatePremium
Extract only ERROR records from a mixed log.
- #166Extract error log entries: No errorsIntermediatePremium
Report a zero count when the log contains only informational records.
- #167Replace a word in text: Update a configuration noteIntermediatePremium
Replace every old environment name in a line.
- #168Replace a word in text: No matching wordIntermediatePremium
Leave text unchanged and report zero replacements when the target is absent.
- #169Divide safely with exceptions: Valid divisionIntermediatePremium
Safely divide two valid numeric inputs.
- #170Divide safely with exceptions: Zero denominatorIntermediatePremium
Return a helpful message instead of crashing on division by zero.
- #171Validate integer input: Accept signed integerIntermediatePremium
Accept a valid signed integer from a form field.
- #172Validate integer input: Reject decimal textIntermediatePremium
Reject a decimal string when the field specifically requires an integer.
- #173Parse key-value configuration: Application settingsIntermediatePremium
Parse and alphabetize a small configuration block.
- #174Parse key-value configuration: Value contains equalsIntermediatePremium
Keep later equals signs as part of the configuration value.
- #175Summarize JSON orders: Two JSON ordersIntermediatePremium
Summarize quantity and value from an API-style JSON response.
- #176Summarize JSON orders: Empty responseIntermediatePremium
Return zero totals for an empty JSON array.
- #177Calculate days between dates: Project durationIntermediatePremium
Find the number of days between project start and finish dates.
- #178Calculate days between dates: Cross a leap dayIntermediatePremium
Let the datetime module handle February 29 correctly.
- #179Count file extensions: Mixed project filesIntermediatePremium
Count extensions in a small project folder listing.
- #180Count file extensions: Case and extensionless filesIntermediatePremium
Combine extension case and label a file that has no suffix.