Python (Fall 2026) Module 6-8: A6 Explanation
Watch on YouTube →
Overview
Bill Moseley explains how to build a Python ATM simulator with savings and checking balances, a transaction loop, and menu options for deposits, withdrawals, and balance checks. He demonstrates account selection and deposit logic, formatted currency output, and input validation, then challenges students to implement withdrawal safeguards and optionally replace separate balance variables with a dictionary.
Key takeaways
- Python input() returns strings, so transaction amounts must be converted to floats before adding to or subtracting from account balances.
- A withdrawal must verify that the selected account contains at least the requested amount before changing its balance, preventing negative balances.
- Using lower() and checking input membership in ('s', 'c') creates a simple validation loop that accepts lowercase account shortcuts and rejects other entries.
- The :.2f format specifier displays monetary values with exactly two decimal places, while a dollar sign makes balance output clearer.
- A dictionary keyed by account name can replace separate checking and savings variables, making it easier to iterate over accounts or add new ones.
Chapters
- Track checking and savings balances separately, starting with sample amounts such as $100.31 and $500.99.
- Use a main while loop to offer deposits, withdrawals, and balance checks, then ask whether the user wants another transaction.
- Check that an account has enough money before a withdrawal so neither balance falls below zero.
- Convert numeric input from strings before doing arithmetic, and use string.rjust to align displayed values.
- Moseley demonstrates menu options for deposits, withdrawals, and checking balances, with a triple-quoted string for a readable menu.
- Prompt users to select savings or checking, using S and C as recognizable account shortcuts.
- Normalize account input with lower() and use membership in a tuple such as ('s', 'c') to repeat the prompt until the selection is valid.
- A break exits the account-selection loop after valid input, allowing the program to continue with the transaction.
- Convert the deposit amount to a float, add it to the selected balance with +=, and report the deposit and updated balance.
- Format currency with a dollar sign and :.2f so amounts display with two decimal places.
- Complete withdrawals by checking available funds first, and implement balance checking for one or both accounts.
- As an optional extension, store account names and balances in a dictionary to support loops and adding accounts without separate variables.
Transcript excerpt
0:00 Okay, so let's talk about A5. Short lecture today, because this is a more involved assignment. And this assignment is going to combine a lot of the different stuff that we've talked about, including some of the concepts and structures that we used with the number guessing game in S5, when I showed you sort of how to put, put an if statement inside a loop and so on. Actually, this is, there we go. ATM machine. So, the ATM simulator. I know a lot of us don't necessarily go to the ATM these days, because you can do most things electronically through apps, but the ATM is an interface to your bank. And you can see here, I'm starting you out
0:58 with a fairly generous amount of code that will allow you to sort of piggyback on my structure. So, what I want you to do with this is, you need to create an ATM machine simulator where the user can check the balance of their savings and their checking account, or make a deposit, or withdraw money from either account. Okay, so there's two accounts. Each one is represented by a different variable. And with those accounts, I want you to be able to add money and to take money out. Now, there's one extra step when you are withdrawing money, and that is, you need to make sure that you have enough money in the account to withdraw the amount
1:56 of money that you're asking to withdraw. So, the balance cannot go below zero. So, you can't have a negative balance in your checking account or your savings account. I want you to use string.rjust to make the, the numbers line up properly on the right hand side the way I showed you. I want you to work on making the UI look good and presentable. I know that that's subjective,
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.