Python · Real Python

Mini Problem Solving — Practice Questions

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

Q1Student ManagementEasy

Define a Student class storing name and three subject scores, with an average() method.

Q2Bank AccountEasy

Define a BankAccount class with a balance and a deposit(amount) method.

Q3ATMEasy

Write a function authenticate(entered_pin, correct_pin) returning whether they match.

Q4LibraryEasy

Define a Book class with title, author, and is_available (starting True).

Q5QuizEasy

Write a function check_answer(question, user_answer) where question is a dict with a "answer" key, returning whether they match.

Q6Expense TrackerEasy

Add a single expense (category, amount) as a dict to a list, then print it.

Q7Contact BookEasy

Add a single contact to a dictionary keyed by name, storing phone and email.

Q8Student ManagementEasy

Write a function letter_grade(average) returning A/B/C/F for a given Student's average.

Q9Bank AccountEasy

Add a withdraw(amount) method to BankAccount that only succeeds if funds are sufficient, returning True/False.

Q10ATMEasy

Write a function display_balance(balance) that prints it formatted as currency.

Q11Student ManagementMedium

Build a StudentManager class holding a list of Student objects, with add_student() and find_by_name().

Q12Bank AccountMedium

Add transaction logging to BankAccount: every deposit/withdraw appends a description to self.history.

Q13ATMMedium

Build an ATM class wrapping a BankAccount, requiring correct PIN authentication before withdraw() is allowed.

Q14LibraryMedium

Build a Library class holding a list of Books, with add_book() and find_book(title).

Q15LibraryMedium

Add checkout_book(title) and return_book(title) methods to Library, toggling is_available.

Q16QuizMedium

Build a Quiz class holding a list of question dicts, with a score(user_answers) method comparing them positionally.

Q17Expense TrackerMedium

Build an ExpenseTracker class with add_expense(category, amount) and total().

Q18Expense TrackerMedium

Add a totals_by_category() method to ExpenseTracker returning a dict summing amounts per category.

Q19Contact BookMedium

Build a ContactBook class with add_contact() and search_contact(name).

Q20Contact BookMedium

Add delete_contact(name) and list_all() methods to ContactBook.

Q21Student ManagementMedium

Add a class_average() method to StudentManager returning the average of every student's average.

Q22Bank AccountMedium

Build a Bank class managing multiple BankAccounts in a dict keyed by account number, with create_account().

Q23ATMMedium

Add a PIN-change feature to ATM: change_pin(old_pin, new_pin) only succeeds if old_pin is correct.

Q24LibraryMedium

Add list_available_books() to Library, filtering to only books currently is_available.

Q25LibraryMedium

Add search_by_author(author) to Library, returning every matching book's title.

Q26QuizMedium

Support multiple-choice questions: each question dict has "options" (a list) and "correct_index", and score against a list of selected indices.

Q27QuizMedium

Given a raw score and total question count, compute a percentage and print "Pass"/"Fail" at a 50% threshold.

Q28Expense TrackerMedium

Given expenses with a "month" field, build a monthly summary dict totaling spend per month.

Q29Contact BookMedium

Add update_contact(name, phone=None, email=None) to ContactBook, updating only the fields provided.

Q30Student ManagementMedium

Add a top_student() method to StudentManager returning the student with the highest average.

Q31Student ManagementHard

Define InvalidScoreError(Exception) and raise it from add_score(score) if the score isn't between 0 and 100.

Q32Bank AccountHard

Define InsufficientFundsError(Exception) and raise it from withdraw(), catching it at the call site.

Q33ATMHard

Lock an ATM account after 3 consecutive wrong PIN attempts, refusing further attempts once locked.

Q34LibraryHard

Given a due_date and today's date, compute an overdue fine at $1/day using the datetime module.

Q35LibraryHard

Define BookUnavailableError(Exception) and raise it from checkout_book() when the book is already checked out.

Q36QuizHard

Randomize the order of a quiz's questions each run using random.shuffle(), while still scoring correctly against the SHUFFLED order.

Q37QuizHard

Build a per-question results report (question text, given answer, correct answer, was it right) instead of just a single score number.

Q38Expense TrackerHard

Given a budget per category, print a warning whenever a category's running total exceeds its budget.

Q39Expense TrackerHard

Persist expenses to a CSV file on save, and reload them on startup.

Q40Contact BookHard

Define DuplicateContactError(Exception) and raise it if add_contact() is called with a phone number that's already stored under a different name.

Q41Mini-ProjectMini-Project

Build a full "Student Management System": add, search, remove students, and print a class report, all behind a menu loop.

Q42Mini-ProjectMini-Project

Build a full "Bank + ATM System" with PIN authentication, deposit, withdraw, and balance check, in a menu loop.

Q43Mini-ProjectMini-Project

Build a full "Library Management System" supporting add, checkout, return, and search, with overdue-fine calculation.

Q44Mini-ProjectMini-Project

Build a full "Quiz Application" with multiple-choice questions, randomized order, scoring, and a pass/fail result.

Q45Mini-ProjectMini-Project

Build a full "Expense Tracker App" that persists to a file, supports adding expenses, and prints a category breakdown with budget warnings.

Q46InterviewInterview

Discuss why a Student Management System built with classes is easier to extend safely than one built purely from raw dicts/lists, demonstrating a validation rule that a class enforces automatically.

Q47InterviewInterview

Discuss why an ATM should call account.withdraw() rather than directly mutating account.balance -= amount, tying it back to encapsulation.

Q48InterviewInterview

Discuss why raising a custom BookUnavailableError from checkout_book() is better API design than silently returning False, demonstrating both call sites.

Q49InterviewInterview

Discuss the tradeoffs between in-memory-only, CSV, and JSON persistence for a Contact Book, demonstrating a quick JSON save/load.

Q50CapstoneInterview

Build a "Unified Mini-System Report" — the most complete demonstration in this module. Combine a small slice of the Student, Bank, and Contact Book systems into one script: create a student with a linked bank account and a linked contact entry, persist everything to JSON, then reload and print a full profile report.

Still stuck on something?

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

Book a Free Session