Mini Problem Solving — Practice Questions
50 questions. Try each one yourself before checking the answer.
Define a Student class storing name and three subject scores, with an average() method.
Define a BankAccount class with a balance and a deposit(amount) method.
Write a function authenticate(entered_pin, correct_pin) returning whether they match.
Define a Book class with title, author, and is_available (starting True).
Write a function check_answer(question, user_answer) where question is a dict with a "answer" key, returning whether they match.
Add a single expense (category, amount) as a dict to a list, then print it.
Add a single contact to a dictionary keyed by name, storing phone and email.
Write a function letter_grade(average) returning A/B/C/F for a given Student's average.
Add a withdraw(amount) method to BankAccount that only succeeds if funds are sufficient, returning True/False.
Write a function display_balance(balance) that prints it formatted as currency.
Build a StudentManager class holding a list of Student objects, with add_student() and find_by_name().
Add transaction logging to BankAccount: every deposit/withdraw appends a description to self.history.
Build an ATM class wrapping a BankAccount, requiring correct PIN authentication before withdraw() is allowed.
Build a Library class holding a list of Books, with add_book() and find_book(title).
Add checkout_book(title) and return_book(title) methods to Library, toggling is_available.
Build a Quiz class holding a list of question dicts, with a score(user_answers) method comparing them positionally.
Build an ExpenseTracker class with add_expense(category, amount) and total().
Add a totals_by_category() method to ExpenseTracker returning a dict summing amounts per category.
Build a ContactBook class with add_contact() and search_contact(name).
Add delete_contact(name) and list_all() methods to ContactBook.
Add a class_average() method to StudentManager returning the average of every student's average.
Build a Bank class managing multiple BankAccounts in a dict keyed by account number, with create_account().
Add a PIN-change feature to ATM: change_pin(old_pin, new_pin) only succeeds if old_pin is correct.
Add list_available_books() to Library, filtering to only books currently is_available.
Add search_by_author(author) to Library, returning every matching book's title.
Support multiple-choice questions: each question dict has "options" (a list) and "correct_index", and score against a list of selected indices.
Given a raw score and total question count, compute a percentage and print "Pass"/"Fail" at a 50% threshold.
Given expenses with a "month" field, build a monthly summary dict totaling spend per month.
Add update_contact(name, phone=None, email=None) to ContactBook, updating only the fields provided.
Add a top_student() method to StudentManager returning the student with the highest average.
Define InvalidScoreError(Exception) and raise it from add_score(score) if the score isn't between 0 and 100.
Define InsufficientFundsError(Exception) and raise it from withdraw(), catching it at the call site.
Lock an ATM account after 3 consecutive wrong PIN attempts, refusing further attempts once locked.
Given a due_date and today's date, compute an overdue fine at $1/day using the datetime module.
Define BookUnavailableError(Exception) and raise it from checkout_book() when the book is already checked out.
Randomize the order of a quiz's questions each run using random.shuffle(), while still scoring correctly against the SHUFFLED order.
Build a per-question results report (question text, given answer, correct answer, was it right) instead of just a single score number.
Given a budget per category, print a warning whenever a category's running total exceeds its budget.
Persist expenses to a CSV file on save, and reload them on startup.
Define DuplicateContactError(Exception) and raise it if add_contact() is called with a phone number that's already stored under a different name.
Build a full "Student Management System": add, search, remove students, and print a class report, all behind a menu loop.
Build a full "Bank + ATM System" with PIN authentication, deposit, withdraw, and balance check, in a menu loop.
Build a full "Library Management System" supporting add, checkout, return, and search, with overdue-fine calculation.
Build a full "Quiz Application" with multiple-choice questions, randomized order, scoring, and a pass/fail result.
Build a full "Expense Tracker App" that persists to a file, supports adding expenses, and prints a category breakdown with budget warnings.
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.
Discuss why an ATM should call account.withdraw() rather than directly mutating account.balance -= amount, tying it back to encapsulation.
Discuss why raising a custom BookUnavailableError from checkout_book() is better API design than silently returning False, demonstrating both call sites.
Discuss the tradeoffs between in-memory-only, CSV, and JSON persistence for a Contact Book, demonstrating a quick JSON save/load.
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