Build a Simple ATM Machine Simulator in Python — Step-by-Step Guide for Beginners
So you've learned Python basics — variables, if-else, loops. Now you're thinking: "What can I actually build with this?" That's exactly the question every beginner faces. And the answer? Build something that feels real, like an ATM machine simulator. It's simple enough to finish in an hour, but packed with all the core concepts you need to move forward.
In this tutorial, we'll create a console-based ATM system in Python that lets users log in with a PIN, check balance, deposit money, withdraw cash, and exit — just like a real ATM. No external libraries, no complex setup. Just you, your terminal, and some Python magic.
If you're new to Python, you might also want to check out our Python programming guide for beginners before diving in.
What You'll Learn From This Project
- How to use variables and data types (float for balance, string for PIN)
- Conditional statements (if-elif-else) to handle user choices
- Loops (while loop) to keep the ATM menu running until exit
- User input handling and type conversion (string to float for amounts)
- Basic authentication logic (PIN verification)
- How to structure a real‑world interactive program
These are the same patterns used in larger applications. Master them here, and you'll be ready for more advanced projects.
Project Overview: Features of Our ATM Simulator
Our ATM will have the following features. Think of it as a stripped‑down version of what you see at your bank — but running in your terminal.
- User Login: Only users who enter the correct 4‑digit PIN can access the account.
- Check Balance: Displays the current balance (starting at ₹1000 or $1000 — you decide).
- Deposit Money: Adds any positive amount to the balance.
- Withdraw Money: Deducts the amount if sufficient balance exists; otherwise shows an error.
- Exit: Ends the session with a friendly goodbye message.
The program will loop continuously after login, showing the menu again after each transaction, until the user chooses to exit.
Full Python Code for ATM Simulator
Copy and paste the code below into any Python environment (IDLE, VS Code, or even an online editor). Then run it and test yourself.
# Simple ATM Machine Simulator
# Created by DomeBytes
print("===== Welcome to Python ATM Simulator =====")
# Default credentials
pin = "1234"
balance = 1000.0 # Starting balance
# Login Section
user_pin = input("Enter your 4-digit PIN: ")
if user_pin == pin:
while True:
print("\n===== ATM Menu =====")
print("1. Check Balance")
print("2. Deposit Money")
print("3. Withdraw Money")
print("4. Exit")
choice = input("\nEnter your choice (1-4): ")
if choice == "1":
print(f"\n💰 Your current balance is: ₹{balance:.2f}")
elif choice == "2":
amount = float(input("\nEnter amount to deposit: ₹"))
if amount > 0:
balance += amount
print(f"\n✅ ₹{amount:.2f} deposited successfully!")
print(f"New balance: ₹{balance:.2f}")
else:
print("\n❌ Invalid amount. Please enter a positive number.")
elif choice == "3":
amount = float(input("\nEnter amount to withdraw: ₹"))
if amount <= 0:
print("\n❌ Invalid amount. Please enter a positive number.")
elif amount <= balance:
balance -= amount
print(f"\n✅ Withdrawn ₹{amount:.2f}.")
print(f"Remaining balance: ₹{balance:.2f}")
else:
print("\n❌ Insufficient balance! You cannot withdraw more than your current balance.")
elif choice == "4":
print("\n🙏 Thank you for using Python ATM! Have a great day.")
break
else:
print("\n❌ Invalid option! Please choose 1, 2, 3, or 4.")
else:
print("\n❌ Incorrect PIN! Access Denied.")
Step-by-Step Explanation: How the Code Works
1. Storing Initial Data
We set two variables: pin = "1234" (as a string) and balance = 1000.0 (as a float). The PIN is a string because it may have leading zeros, and we compare it directly with user input.
2. Login Authentication
The program asks for a 4‑digit PIN using input(). If it matches, the user enters the main menu loop. If not, the program prints "Access Denied" and ends. This is a simple but effective authentication model.
3. Infinite Loop with While True
while True: keeps showing the menu until the user chooses option 4 (break). Inside the loop, we use if-elif-else to handle each choice.
4. Deposit Logic
We take a float input and add it to the balance. Notice we also check if the amount is positive — a good practice to prevent negative deposits.
5. Withdraw Logic
We check two conditions: amount must be positive, and amount must not exceed the balance. Only then we deduct. Otherwise, we show appropriate error messages.
6. Exiting the Loop
When the user selects option 4, break exits the while loop, and the program prints a thank‑you message.
For more practice with Python loops and conditionals, try building a drinks ordering app — it's another beginner‑friendly project.
Real-World Use Cases & Extensions
This basic simulator can be extended into a more realistic application. Here are some ideas:
- Multiple users: Store PINs and balances in a dictionary to support multiple accounts.
- Transaction history: Keep a list of all deposits and withdrawals.
- PIN change feature: Allow users to change their PIN after login.
- Minimum balance requirement: Prevent withdrawals that would drop below a certain limit.
- Save data to a file: Use JSON or CSV to persist balances between runs.
- Add a GUI: Use Tkinter or PyQt to turn this into a desktop application.
If you're interested in building more interactive Python apps, check out our tutorial on building a simple payment app.
Common Beginner Mistakes & How to Fix Them
- Indentation errors: Python relies on indentation. Make sure the code inside the
ifandwhileblocks is properly indented (4 spaces per level). - Comparing string to integer: The PIN is a string, so
user_pin == 1234will always be False. Keep both as strings or convert usingint(). - Forgetting to convert input for amounts:
input()returns a string. Usefloat()to convert deposit/withdraw amounts. - Infinite loop: If you forget
breakinside option 4, the loop will never exit. Always include an exit condition.
Video Tutorial (Watch & Code Along)
👉 Full article and code: DomeBytes ATM Project Page
Frequently Asked Questions (FAQ)
1. Can I run this ATM simulator on my phone?
Yes! You can use apps like Pydroid 3 (Android) or Pythonista (iOS) to run Python code on your phone. The code is standard Python and works anywhere.
2. How do I add more than one user?
Use a dictionary: users = {"1234": 1000.0, "5678": 2500.0}. Then ask for PIN, check if it exists in the dictionary, and retrieve the corresponding balance.
3. Why does my deposit or withdraw give an error?
Most likely you forgot to convert the input to float. Use amount = float(input("Enter amount: ")). Also ensure you're not entering letters or symbols.
4. How can I save the balance after closing the program?
You need file handling. Write the balance to a text file before exit and read it when the program starts. We have a tutorial on data recovery that also covers file basics.
5. Is this project good for a school submission?
Absolutely. It's a classic beginner project that demonstrates understanding of variables, conditionals, loops, and user input. Add comments and a short report explaining the logic.
Related Posts You Might Like
Final Thoughts
Congratulations! You've just built your own ATM machine simulator in Python. It may seem small, but this project teaches you the exact flow of real applications: authentication, menu loops, data updates, and graceful exit. Every professional developer started with projects like this.
Now take it further: add a GUI using Tkinter, or connect it to a database. The skills you've learned here will directly apply. Keep coding, and don't forget to subscribe to DomeBytes on YouTube for more Python tutorials, tips, and full projects.
Music credit: Track: LXNGVX, Warriyo - Mortals Funk Remix. Music provided by NoCopyrightSounds.
