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

Files, Exceptions, and Modules Python practice problems

Reading and writing text data, handling predictable failures, imports, and safe input boundaries.

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

  • text file · statistics
  • csv · module
  • logs · filtering
  • replace · text processing
  • try except · ZeroDivisionError
PRACTICE OUTCOME

What this topic builds

Learn the idea once, use it across the exercises, and explain why your approach works.

ORDERED PRACTICE

All 20 problems in this topic

Work from top to bottom to build the concept gradually.

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

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

    StarterPremium
  2. #134
    Count lines, words, and characters: Blank line counts

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

    StarterPremium
  3. #135
    Total values from CSV rows: Small order CSV

    Calculate the total value of three CSV order rows.

    StarterPremium
  4. #136
    Total values from CSV rows: Decimal unit prices

    Keep currency precision across several decimal prices.

    StarterPremium
  5. #137
    Extract error log entries: Mixed application log

    Extract only ERROR records from a mixed log.

    BeginnerPremium
  6. #138
    Extract error log entries: No errors

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

    BeginnerPremium
  7. #139
    Replace a word in text: Update a configuration note

    Replace every old environment name in a line.

    BeginnerPremium
  8. #140
    Replace a word in text: No matching word

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

    BeginnerPremium
  9. #141
    Divide safely with exceptions: Valid division

    Safely divide two valid numeric inputs.

    BeginnerPremium
  10. #142
    Divide safely with exceptions: Zero denominator

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

    BeginnerPremium
  11. #143
    Validate integer input: Accept signed integer

    Accept a valid signed integer from a form field.

    BeginnerPremium
  12. #144
    Validate integer input: Reject decimal text

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

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

    Parse and alphabetize a small configuration block.

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

    Keep later equals signs as part of the configuration value.

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

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

    IntermediatePremium
  16. #148
    Summarize JSON orders: Empty response

    Return zero totals for an empty JSON array.

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

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

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

    Let the datetime module handle February 29 correctly.

    AdvancedPremium
  19. #151
    Count file extensions: Mixed project files

    Count extensions in a small project folder listing.

    AdvancedPremium
  20. #152
    Count file extensions: Case and extensionless files

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

    AdvancedPremium