pyPython Practice LabFrom first print to final round
TOPIC 09 OF 18

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.

20 exercises8+ conceptsBeginner → interview context
Start this topic
WHAT YOU WILL PRACTISE

Core concepts

Count lines, words, and charactersTotal values from CSV rowsExtract error log entriesReplace a word in textDivide safely with exceptionsValidate integer inputParse key-value configurationSummarize JSON orders
REUSABLE THINKING

Problem-solving patterns

  • Open or parse safely → validate → handle failure → produce result
INTERVIEW SIGNALS

Reported company tags

IBMAccentureCognizantAmazonGoogleMicrosoft
Community-reported tags are guidance, not guarantees.
ORDERED PRACTICE

All 20 problems in this topic

Work from top to bottom to build the concept gradually.

  1. #161
    Count lines, words, and characters: Analyze a two-line note

    Compute basic statistics for text that could have been read from a file.

    IntermediatePremium
  2. #162
    Count lines, words, and characters: Blank line counts

    Treat a blank line as a line and include the joining newline characters.

    IntermediatePremium
  3. #163
    Total values from CSV rows: Small order CSV

    Calculate the total value of three CSV order rows.

    IntermediatePremium
  4. #164
    Total values from CSV rows: Decimal unit prices

    Keep currency precision across several decimal prices.

    IntermediatePremium
  5. #165
    Extract error log entries: Mixed application log

    Extract only ERROR records from a mixed log.

    IntermediatePremium
  6. #166
    Extract error log entries: No errors

    Report a zero count when the log contains only informational records.

    IntermediatePremium
  7. #167
    Replace a word in text: Update a configuration note

    Replace every old environment name in a line.

    IntermediatePremium
  8. #168
    Replace a word in text: No matching word

    Leave text unchanged and report zero replacements when the target is absent.

    IntermediatePremium
  9. #169
    Divide safely with exceptions: Valid division

    Safely divide two valid numeric inputs.

    IntermediatePremium
  10. #170
    Divide safely with exceptions: Zero denominator

    Return a helpful message instead of crashing on division by zero.

    IntermediatePremium
  11. #171
    Validate integer input: Accept signed integer

    Accept a valid signed integer from a form field.

    IntermediatePremium
  12. #172
    Validate integer input: Reject decimal text

    Reject a decimal string when the field specifically requires an integer.

    IntermediatePremium
  13. #173
    Parse key-value configuration: Application settings

    Parse and alphabetize a small configuration block.

    IntermediatePremium
  14. #174
    Parse key-value configuration: Value contains equals

    Keep later equals signs as part of the configuration value.

    IntermediatePremium
  15. #175
    Summarize JSON orders: Two JSON orders

    Summarize quantity and value from an API-style JSON response.

    IntermediatePremium
  16. #176
    Summarize JSON orders: Empty response

    Return zero totals for an empty JSON array.

    IntermediatePremium
  17. #177
    Calculate days between dates: Project duration

    Find the number of days between project start and finish dates.

    IntermediatePremium
  18. #178
    Calculate days between dates: Cross a leap day

    Let the datetime module handle February 29 correctly.

    IntermediatePremium
  19. #179
    Count file extensions: Mixed project files

    Count extensions in a small project folder listing.

    IntermediatePremium
  20. #180
    Count file extensions: Case and extensionless files

    Combine extension case and label a file that has no suffix.

    IntermediatePremium