ATM Simulator
Learn how to build an ATM simulation using Python variables, conditions, loops, functions and input validation.
1. Project Introduction
An ATM Simulator is a beginner-friendly project that imitates common banking operations.
The application can allow a user to check balance, deposit money, withdraw money and exit the system.
2. Creating the Account Balance
We can use a variable to store the current balance.
balance = 10000
The balance can change whenever money is deposited or withdrawn.
3. Creating a PIN
A simple PIN can be stored for this educational simulation.
correct_pin = "1234"
4. Taking the PIN from the User
pin = input("Enter your PIN: ")
The input is returned as a string, which is useful because PINs are identification values rather than amounts used in arithmetic.
5. Checking the PIN
if pin == correct_pin:
print("Login successful.")
else:
print("Incorrect PIN.")
6. Creating an ATM Menu
After successful login, the user can choose an operation from a menu.
print("1. Check Balance")
print("2. Deposit Money")
print("3. Withdraw Money")
print("4. Exit")
7. Using a While Loop
An ATM should continue showing the menu until the user chooses Exit.
while True:
print("1. Check Balance")
print("2. Deposit")
print("3. Withdraw")
print("4. Exit")
choice = input(
"Enter choice: "
)
8. Checking the Balance
The current balance can simply be displayed.
if choice == "1":
print(
"Balance:",
balance
)
9. Depositing Money
Deposit means adding money to the current balance.
amount = float(
input("Enter deposit amount: ")
)
if amount > 0:
balance += amount
print(
"Deposit successful."
)
10. Withdrawing Money
Withdrawal reduces the current balance.
amount = float(
input("Enter withdrawal amount: ")
)
if amount <= 0:
print("Invalid amount.")
elif amount > balance:
print("Insufficient balance.")
else:
balance -= amount
print("Withdrawal successful.")
11. Checking Insufficient Balance
Before a withdrawal, the program must make sure the requested amount does not exceed the balance.
if amount > balance:
print(
"Insufficient balance."
)
12. Exiting the ATM
if choice == "4":
print("Thank you.")
break
The break statement stops the while loop.
13. Creating Functions
Larger programs are easier to manage when operations are separated into functions.
def show_balance(balance):
print(
"Current Balance:",
balance
)
Similar functions can be created for deposits and withdrawals.
14. Input Validation
User input should always be validated before it is used.
try:
amount = float(
input("Enter amount: ")
)
except ValueError:
print(
"Please enter a valid number."
)
15. Preventing Invalid Deposits
if amount <= 0:
print(
"Amount must be greater than zero."
)
else:
balance += amount
16. Preventing Invalid Withdrawals
if amount <= 0:
print("Invalid amount.")
elif amount > balance:
print(
"Insufficient balance."
)
else:
balance -= amount
17. Complete Project Flow
18. Concepts You Practiced
- Variables
- Strings
- Numbers
- Input
- if / elif / else
- while Loop
- break
- Functions
- try / except
- Arithmetic Operators
- Input Validation
- Basic Banking Logic
19. Run Complete Project 🚀
You have learned the logic behind an ATM simulator. Now open the complete interactive project.
Run Complete Project