Skip to main content
Programming Concepts
  • Home
  • Start Here
  • Learn
  • Practice
  • Projects
  • Glossary
  • About

Practice

Every exercise lives inside its lesson, where it has full context. This page helps you find one by topic, difficulty, or type.

  • Object-Oriented Programmingmoderatecoding

    Add a return_book method to LibraryBook

    Write a method that reverses borrow()'s state change, then trace borrowing, returning, and borrowing again.

    From Objects and Classes · ~10 min

  • Algorithmic Thinking & Problem Solvinggentleshort-answer

    Choose the minimal model for three library questions

    Decide the minimal model needed for three different questions about a library's books.

    From Abstraction and Modeling · ~6 min

  • Object-Oriented Programminggentleshort-answer

    Classify a Thermostat's public and internal members

    Sort a class's methods and attributes into public interface vs. implementation detail.

    From Interfaces and Public Behavior · ~6 min

  • Programming Essentialsgentleshort-answer

    Classify three bugs

    Sort three short examples into syntax error, runtime error, or logic error.

    From Debugging and Testing · ~6 min

  • Object-Oriented Programminggentleshort-answer

    Classify three class pairs as is-a or has-a

    Decide whether three pairs of classes relate by inheritance or composition, and sketch the direction.

    From Class Relationships and Simple Diagrams · ~6 min

  • Algorithmic Thinking & Problem Solvinggentleshort-answer

    Classify three functions by growth rate

    Sort three functions into constant, linear, or quadratic based on their loop structure.

    From Comparing Solutions · ~8 min

  • Object-Oriented Programminggentleshort-answer

    Decide class vs. plain function for three scenarios

    Apply the state-and-behavior test to decide whether three scenarios justify a class or a plain function.

    From When OOP Helps — and When It Does Not · ~8 min

  • Algorithmic Thinking & Problem Solvingmoderateprediction

    Decide most_vowels's empty-list behavior on purpose

    Predict what an unspecified edge case does by accident, then make the decision explicit in code.

    From Inputs, Outputs, Constraints, and Edge Cases · ~10 min

  • Algorithmic Thinking & Problem Solvinggentleshort-answer

    Decompose an email-checking problem

    Split a vague problem into three or four subproblems, each with one job.

    From Problem Decomposition · ~8 min

  • Algorithmic Thinking & Problem Solvingmoderatecoding

    Decompose the undecomposed receipt program

    Compare a monolithic version of the receipt calculation to the decomposed one, then rewrite it as functions.

    From Problem Decomposition · ~10 min

  • Algorithmic Thinking & Problem Solvingmoderateprediction

    Diagnose a quadratic slowdown in a growing report

    Predict why a quadratic duplicate-checker got dramatically slower as input grew, then swap in the linear version.

    From Comparing Solutions · ~8 min

  • Programming Essentialsgentleshort-answer

    Evaluate four expressions by hand

    Apply operator precedence and parentheses to evaluate four short arithmetic expressions.

    From Expressions · ~6 min

  • Object-Oriented Programmingmoderateprediction

    Fix a backwards is-a diagram

    Predict why a Manager/Employee diagram is drawn backwards, then redraw it correctly.

    From Class Relationships and Simple Diagrams · ~6 min

  • Algorithmic Thinking & Problem Solvingmoderateprediction

    Fix a binary search on unsorted usernames

    Predict why binary_search reports a present username as missing on unsorted data, then fix it.

    From Search Strategies · ~10 min

  • Foundational Data Structuresmoderateprediction

    Fix a graph traversal that never tracks visited nodes

    Predict why a traversal with no visited tracking loops forever on a cyclic graph, then fix it.

    From Trees and Graphs as a First Look · ~10 min

  • Foundational Data Structuresmoderateprediction

    Fix a node silently dropped from a chain

    Predict why a node disappears from traversal after an insertion, then fix the missing reference.

    From Linked Structures as a Mental Model · ~8 min

  • Programming Essentialsmoderateprediction

    Fix a running total that never escapes its function

    Predict why a return value that's never captured leaves a NameError outside the function, then fix it.

    From Scope · ~8 min

  • Foundational Data Structuresmoderateprediction

    Fix a ticket queue that serves the newest first

    Predict why pop() serves tickets in the wrong order, then fix it with pop(0).

    From Stacks and Queues · ~8 min

  • Programming Essentialsmoderatecoding

    Fix average() and write tests for it

    Fix a logic error in an averaging function, then write assertions including an edge case.

    From Debugging and Testing · ~10 min

  • Programming Essentialsmoderateprediction

    Fix is_even so its result can be used

    Predict why a function that prints instead of returning breaks a caller's if statement, then fix it.

    From Functions · ~8 min

  • Programming Essentialsmoderateprediction

    Fix the broken swap

    Predict why a two-line swap fails, then fix it using a third variable.

    From Variables and State · ~8 min

  • Foundational Data Structuresmoderateprediction

    Fix the crashing loyalty-points lookup

    Predict why a dictionary lookup raises KeyError for a new customer, then fix it with .get().

    From Lists and Dictionaries · ~8 min

  • Programming Essentialsmoderateprediction

    Fix the discount-then-tax calculation

    Predict why a missing parenthesis causes tax to be computed on the wrong amount, then fix it.

    From Expressions · ~8 min

  • Programming Essentialsmoderateprediction

    Fix the infinite while loop

    Predict why a while loop never stops, then add the missing line that fixes it.

    From Loops · ~8 min

  • Programming Essentialsmoderateprediction

    Fix the receipt total

    Predict whether a checkout calculation raises a TypeError, then fix it.

    From Values and Types · ~8 min

  • Programming Essentialsmoderateprediction

    Fix the temperature labeler

    Predict why separate if statements misclassify a temperature, then rewrite them as one elif chain.

    From Conditions · ~8 min

  • Foundational Data Structuresgentleshort-answer

    Identify a tree's root, leaves, and a parent

    Given a small three-level tree built from node dictionaries, identify its root, leaves, and one node's parent.

    From Trees and Graphs as a First Look · ~8 min

  • Algorithmic Thinking & Problem Solvinggentlecoding

    Improve total() and re-verify it

    Replace a manual summing loop with sum(), then confirm the original assertion still passes.

    From Iterative Improvement · ~6 min

  • Algorithmic Thinking & Problem Solvingmoderateprediction

    Isolate which of three changes broke a test

    Predict why three simultaneous changes make a failing test hard to diagnose, then reapply them one at a time.

    From Iterative Improvement · ~10 min

  • Foundational Data Structuresgentleshort-answer

    Match five scenarios to the structures that fit

    Apply the four-question framework to pick the best structure for five different scenarios.

    From Choosing a Structure · ~8 min

  • Programming Essentialsgentleshort-answer

    Name the types

    For five given values, write down each one's type before checking.

    From Values and Types · ~5 min

  • Foundational Data Structuresgentleshort-answer

    Pick a list or a dictionary for three scenarios

    Decide whether a list or dictionary fits three data scenarios, and explain why.

    From Lists and Dictionaries · ~6 min

  • Object-Oriented Programmingmoderateprediction

    Replace a direct _balance edit with deposit()

    Predict why bypassing deposit() is risky even when it currently works, then fix the code.

    From Encapsulation · ~8 min

  • Object-Oriented Programmingmoderatecoding

    Replace a forgotten isinstance branch with polymorphism

    Predict why a new Director class silently gets the wrong bonus, then refactor to a polymorphic bonus() method.

    From Polymorphism · ~10 min

  • Foundational Data Structuresmoderatecoding

    Replace a manually-searched username list with a set

    Predict why a list-based membership check gets slower as it grows, then replace it with a set.

    From Choosing a Structure · ~8 min

  • Object-Oriented Programmingmoderatecoding

    Replace a misused inheritance with composition

    Predict why PremiumMember inheriting from Discount misrepresents the relationship, then refactor to composition.

    From Inheritance · ~10 min

  • Object-Oriented Programmingmoderateprediction

    Replace direct attribute access with borrow()

    Predict the risk of bypassing an object's interface, then rewrite the code to use it.

    From Interfaces and Public Behavior · ~8 min

  • Object-Oriented Programmingmoderatecoding

    Rewrite Member to compose Account instead of duplicating it

    Predict the risk of reimplementing balance logic directly, then refactor Member to delegate to a composed Account.

    From Composition · ~10 min

  • Object-Oriented Programmingmoderatecoding

    Simplify DiscountCalculator into a plain function

    Predict why a stateless class adds no value here, then rewrite it as a plain function.

    From When OOP Helps — and When It Does Not · ~8 min

  • Algorithmic Thinking & Problem Solvinggentleshort-answer

    Specify a highest-score problem fully

    Write down inputs, outputs, constraints, and edge cases for a "find the highest score" problem.

    From Inputs, Outputs, Constraints, and Edge Cases · ~8 min

  • Foundational Data Structuresmoderateprediction

    Speed up order-ID membership checks with a set

    Predict why a growing list makes membership checks slower, then rewrite using a set.

    From Sets and Uniqueness · ~8 min

  • Programming Essentialsmoderateprediction

    Stop get_sorted from mutating the caller's list

    Predict why sorting a list parameter changes the caller's original, then fix it with .copy().

    From Mutability and References · ~10 min

  • Object-Oriented Programminggentletrace

    Trace a bonus() loop across three subclasses

    Trace what each of three Employee subclasses returns from a shared bonus() call in a loop.

    From Polymorphism · ~8 min

  • Algorithmic Thinking & Problem Solvinggentletrace

    Trace a counting algorithm, including an empty list

    Trace pseudocode that counts matching values, for both a normal list and the empty-list edge case.

    From Pseudocode and Tracing · ~6 min

  • Foundational Data Structuresgentletrace

    Trace a linked chain being built node by node

    Trace the chain of next references after each line links a new node in.

    From Linked Structures as a Mental Model · ~8 min

  • Object-Oriented Programminggentletrace

    Trace a member's balance through three fines

    Trace the composed Account's balance as pay_fine delegates to it three times, including a refused withdrawal.

    From Composition · ~8 min

  • Programming Essentialsgentletrace

    Trace a running total through a for loop

    Trace total after each pass of a for loop that subtracts amounts from a list.

    From Loops · ~6 min

  • Foundational Data Structuresgentletrace

    Trace a set built from duplicate words

    Trace a set's contents as four .add() calls run, including a repeated value.

    From Sets and Uniqueness · ~6 min

  • Programming Essentialsgentletrace

    Trace a total by hand

    Trace three assignments, including one where a variable appears on both sides.

    From Variables and State · ~5 min

  • Object-Oriented Programminggentletrace

    Trace an account through deposits and withdrawals

    Trace _balance through a sequence of deposit and withdraw calls, including one that must be checked against the current balance.

    From Encapsulation · ~8 min

  • Object-Oriented Programminggentletrace

    Trace inherited vs. overridden area()

    Trace a base Shape's area() against a Square subclass's overridden version.

    From Inheritance · ~8 min

  • Algorithmic Thinking & Problem Solvinggentletrace

    Trace linear and binary search side by side

    Trace both search strategies looking for the same target and compare how many comparisons each takes.

    From Search Strategies · ~8 min

  • Programming Essentialsgentletrace

    Trace shared list references vs. independent numbers

    Trace how a mutated shared list is visible through both names, contrasted with independent number variables.

    From Mutability and References · ~8 min

  • Programming Essentialsgentletrace

    Trace the cinema pricing rules

    For four ages, work out which branch of an if/elif/else chain runs.

    From Conditions · ~6 min

  • Programming Essentialsgentletrace

    Trace three calls to area()

    Trace how width and height map to a return value across three function calls.

    From Functions · ~6 min

  • Foundational Data Structuresgentletrace

    Trace three pops from a stack

    Trace what each pop() call removes and returns from a stack of three numbers.

    From Stacks and Queues · ~6 min

  • Object-Oriented Programminggentletrace

    Trace two independent LibraryBook instances

    Trace is_on_loan for two separate book instances as borrow() is called on each.

    From Objects and Classes · ~8 min

  • Programming Essentialsgentletrace

    Trace which names are visible where

    Decide whether each print line succeeds or raises a NameError, for a program mixing global and local names.

    From Scope · ~6 min

  • Algorithmic Thinking & Problem Solvingmoderatecoding

    Translate count_negatives from pseudocode

    Turn traced pseudocode into a working Python function, then trace the function itself to confirm it.

    From Pseudocode and Tracing · ~10 min

  • Algorithmic Thinking & Problem Solvingmoderatecoding

    Trim an over-modeled average function

    Predict why tracking names and a highest scorer is unnecessary for a simple average, then simplify the function.

    From Abstraction and Modeling · ~8 min

Programming Concepts teaches transferable ideas using Python as the example language.

  • About
  • Glossary
  • Curriculum