Sharing notes from my ongoing learning journey — what I build, break and understand along the way.
Building a Simple Python ATM Program with Loops and User Interaction
How I Built a Simple ATM Program in Python (Step-by-Step)
This week I wanted to build something small but practical in Python: an ATM simulation. The goal wasn’t to impress anyone, just to reinforce what I already learned and get more comfortable with some new things — especially the while True
loop and .format()
method.
By the time I finished, I had a simple, working ATM program where the user could check balance, deposit, withdraw, and exit.
What Was My Goal?
The basic idea was:
- The user sees a simple ATM-style menu.
- They can choose to check their balance, deposit, withdraw, or exit the program.
- The balance updates in real-time with every operation.
- For now, I didn’t use any database — everything runs in memory with plain Python.
What Is while True
in Python?
The while True:
loop is a way to keep your code running indefinitely — or until you decide to stop it with break
.
while True:
# This block keeps repeating forever
Inside the loop, I check if the user typed 'q'
. If so, I use break
to stop the loop and end the session. This pattern is really useful for menu-based programs like this one.
What Is .format()
Used For?
The .format()
method lets you insert variables into strings in a clean and readable way.
For example:
name = "Alex"
print("Hello, {}".format(name)) # Output: Hello, Alex
I used it in my program to show the user’s balance like this:
print("Your balance is {} USD.".format(balance))
It makes the messages dynamic and way easier to manage.
What Does continue
Do?
Here’s something I used that I hadn’t used much before: continue
.
When a user tries to withdraw more money than they have, the program should skip the rest of that iteration and go straight to the next one. That’s what continue
does.
if balance - amount < 0:
print("Insufficient funds.")
continue
It stops that round of the loop early and starts again from the top. No money is withdrawn, and the program just re-prompts for input.
Full Code: Python ATM Program
print("""*************************************************
Welcome to the ATM.
Available operations:
1. Check Balance
2. Deposit Money
3. Withdraw Money
Press 'q' to quit.
*************************************************
""")
balance = 1000 # Starting balance
while True:
action = input("Select an option: ")
if action == "q":
print("Thanks for using our ATM.")
break
elif action == "1":
print("Your balance is {} USD.".format(balance))
elif action == "2":
amount = int(input("Enter the amount to deposit: "))
balance += amount
print("Your new balance is {} USD.".format(balance))
elif action == "3":
amount = int(input("Enter the amount to withdraw: "))
if balance - amount < 0:
print("Insufficient funds.")
continue # Skip the rest and go back to the top
balance -= amount
print("Your new balance is {} USD.".format(balance))
else:
print("Invalid operation.")
How It Works
Here’s how the program runs:
- A welcome message and menu appear.
- The user can choose:
"1"
→ check balance"2"
→ deposit money"3"
→ withdraw money"q"
→ quit the program
- If the user enters
"3"
and tries to withdraw more than they have, the program shows an error and skips the withdrawal usingcontinue
. - For anything invalid, it shows
"Invalid operation."
In Short
This project helped me practice:
- Using loops and conditions
- Getting user input and updating values
- Printing dynamic text with
.format()
- Controlling loop behavior with
break
andcontinue
For a beginner like me, it’s a great confidence booster. Next step? I want to connect this to a real database, so users can log in with a username and password, and store balances permanently. But one step at a time