Python · Real Python

Python Coding Challenges — Practice Questions

50 questions. Try each one yourself before checking the answer.

Q1Word Frequency AnalyserEasy

Given a sentence, build a word-frequency dictionary — the foundational piece the full analyser will build on.

Q2Log ParserEasy

Given a log line "2024-06-15 14:30:00 ERROR Failed to connect", extract just the log LEVEL using .split().

Q3Sudoku ValidatorEasy

Given a single Sudoku row (a list of 9 digits, 0 for empty), check whether it has any DUPLICATE non-zero digits.

Q4Password ManagerEasy

Store a single password entry in a dict keyed by service name, then retrieve it.

Q5CSV AnalyserEasy

Given a CSV file, read just the HEADER row using csv.reader().

Q6Inventory SystemEasy

Add a single item with a quantity to an inventory dictionary.

Q7File OrganiserEasy

Given a filename, extract its extension using os.path.splitext().

Q8Word Frequency AnalyserEasy

Given frequency = {"the": 2, "cat": 1, "mat": 1}, find the MOST common word using max().

Q9Log ParserEasy

Given a list of log lines, count how many are "ERROR" level using .startswith()-style checking on the line's content.

Q10Sudoku ValidatorEasy

Given a Sudoku BOARD (list of 9 rows), extract a single COLUMN as a list, then check it for duplicates.

Q11Word Frequency AnalyserMedium

Read a text file's contents and build a full word-frequency dictionary from it.

Q12Log ParserMedium

Parse a log line into (timestamp, level, message) using .split(maxsplit=...).

Q13Sudoku ValidatorMedium

Given a Sudoku board, extract a single 3x3 BOX (given its top-left row/col) and check it for duplicates.

Q14Password ManagerMedium

Build add_password(vault, service, password) and get_password(vault, service) functions wrapping the dict access.

Q15CSV AnalyserMedium

Given a CSV with a numeric score column, compute the average score using csv.DictReader.

Q16Inventory SystemMedium

Add update_quantity(inventory, item, change) that adjusts an item's stock, removing it entirely if it hits zero.

Q17File OrganiserMedium

Group a folder's files into a dict keyed by extension, WITHOUT moving anything yet (just a preview report).

Q18Word Frequency AnalyserMedium

Build a word-frequency counter that EXCLUDES common stopwords ("the", "is", "a", "an") using a set.

Q19Log ParserMedium

Given log lines each starting with "HH:MM:SS", filter lines that fall within a given time range using string comparison.

Q20Sudoku ValidatorMedium

Combine row, column, and box checks into a single is_valid_sudoku(board) — covering the ROW checks fully, with column/box logic to follow.

Q21Password ManagerMedium

Generate a strong random password using random and string (revisiting the Modules & Packages module).

Q22Password ManagerMedium

Validate a password's strength using re — requiring a digit, an uppercase letter, and at least 8 characters.

Q23CSV AnalyserMedium

Find the ROW with the maximum value in a numeric column, using max() with a key.

Q24CSV AnalyserMedium

Filter CSV rows matching a condition (score >= 90) and write them into a NEW CSV file.

Q25Inventory SystemMedium

Build a "low stock" report: items in inventory below a given threshold.

Q26Inventory SystemMedium

Given an inventory dict AND a prices dict, compute the total value of all stock on hand.

Q27File OrganiserMedium

Fully organize a folder: move every file into an extension-named subfolder (a working version of Q17's preview).

Q28File OrganiserMedium

Rename every file in a folder to a sequential pattern (file_1.txt, file_2.txt, ...), preserving each original extension.

Q29Word Frequency AnalyserMedium

Build a "top N words" report from a word-frequency dictionary using sorted().

Q30Log ParserMedium

Summarize a list of log lines into a count-per-level report (INFO, WARNING, ERROR), formatted and printed.

Q31Sudoku ValidatorHard

Implement the FULL classic is_valid_sudoku(board) — checking all rows, all columns, and all nine 3x3 boxes.

Q32Password ManagerHard

Store password HASHES instead of plaintext, using hashlib.sha256(), and verify a login attempt by hashing and comparing.

Q33Password ManagerHard

Persist a HASHED password vault to a JSON file, then reload it and verify a login attempt against the loaded data.

Q34CSV AnalyserHard

Report which rows in a CSV have MISSING/EMPTY values in any column.

Q35CSV AnalyserHard

Merge two CSVs (students.csv with name, id and scores.csv with id, score) into one combined dataset, joining on id.

Q36Inventory SystemHard

Process a batch of orders, raising a custom OutOfStockError if an order requests more than what's available.

Q37Log ParserHard

Parse a full log file and build an error-count-PER-HOUR report, extracting the hour from each timestamp.

Q38File OrganiserHard

Find potential DUPLICATE files across an entire folder tree by matching both name and size, using os.walk().

Q39Word Frequency AnalyserHard

Build a frequency counter that's robust to PUNCTUATION and CASE, using re to clean the text before counting.

Q40DebuggingHard

The following Sudoku validator ONLY checks rows, silently missing column/box duplicates, so it wrongly approves an invalid board. Find and fix the gap.

def is_valid_sudoku(board):
    for row in board:
        filled = [n for n in row if n != 0]
        if len(filled) != len(set(filled)):
            return False
    return True
Q41Mini-ProjectMini-Project

Build a full "Word Frequency Analyser": read a text file, clean punctuation/case with re, exclude stopwords, and print a top-5 report.

Q42Mini-ProjectMini-Project

Build a full "Log Parser & Analyzer": parse a log file, summarize counts by level, and report the busiest hour for errors.

Q43Mini-ProjectMini-Project

Build a full "Sudoku Validator" tool that not only says valid/invalid but reports the SPECIFIC violation (which row, column, or box failed first).

Q44Mini-ProjectMini-Project

Build a full "Password Manager" with hashed storage, add/verify/list-services operations, all persisted to JSON, behind a menu loop.

Q45Mini-ProjectMini-Project

Build a full "CSV Analyser" that computes count, sum, average, min, and max for EVERY numeric column in a CSV automatically.

Q46InterviewInterview

Explain why passwords should NEVER be stored in plaintext (even in a "just for practice" project), and why a bare sha256 hash isn't fully production-safe either (no salt), demonstrating the gap.

Q47InterviewInterview

Explain why a Sudoku validator's nested loops are still considered O(1) despite "looking like" an algorithm with variable complexity, tying it back to the Algorithms module's Big-O discussion.

Q48InterviewInterview

Explain why a CSV analyser should handle ONE bad row gracefully (skip and log it) rather than crashing the entire analysis, demonstrating with per-row try/except.

Q49InterviewInterview

Explain the "dry-run mode" pattern for a File Organiser (or any destructive tool): print what WOULD happen before actually doing it, demonstrating a dry_run flag.

Q50CapstoneInterview

Build a "Coding Challenges Mastery Report" — the grand-finale demonstration, tying together the ENTIRE 25-topic curriculum. Combine mini versions of a Word Frequency Analyser, a Log Parser, and an Inventory System into one script, using OOP, file I/O, exceptions, collections, and string processing together, printing one final unified report.

Still stuck on something?

Book a free 1-on-1 session and we'll work through it together.

Book a Free Session