Python ATM Program – Complete Project with PIN Verification, Operations, Logs & Extra Concepts
This Python ATM Mini-Project performs Credit, Debit, Balance Check, Repeat Operation and Exit options. The system verifies the user PIN and provides three attempts. After login, the user can perform maximum three operations. A complete transaction log is displayed after exit.
ATM Menu Options
- C → Credit
- D → Debit
- B → Check Balance
- R → Reset Operation Count
- E → Exit
Flow Logic
- Ask user to enter PIN (max 3 attempts)
- If correct, open menu
- User can perform max 3 operations per session
- All transactions are logged
- Show logs on exit
Complete ATM Program (Optimized & Corrected)
pin = "1111"
flag = False
amt = 5000
count = 0
logs = [] # store user operations
# ---------------- PIN VERIFICATION ----------------
for i in range(1, 4):
user_pin = input("Enter PIN Code: ")
if user_pin == pin:
flag = True
break
else:
print("Incorrect PIN! Attempts left:", 3 - i)
if not flag:
print("You entered wrong PIN three times. System Locked!")
exit()
# ---------------- ATM OPERATIONS ----------------
while True:
if count >= 3:
print("\nMaximum operation limit reached! Exiting...")
break
operation = input("""
Choose Operation:
C - Credit
D - Debit
B - Check Balance
R - Reset Operation Count
E - Exit
Enter your choice: """).lower()
# -------- DEBIT --------
if operation == 'd':
debit_amount = int(input("Enter amount to debit: "))
if debit_amount <= amt:
amt -= debit_amount
print(f"Debited ₹{debit_amount}. Available Balance: ₹{amt}")
logs.append(f"Debited: {debit_amount}")
count += 1
else:
print("Insufficient Balance!")
# -------- CREDIT --------
elif operation == 'c':
credit_amount = int(input("Enter amount to credit: "))
amt += credit_amount
print(f"Credited ₹{credit_amount}. Current Balance: ₹{amt}")
logs.append(f"Credited: {credit_amount}")
count += 1
# -------- BALANCE CHECK --------
elif operation == 'b':
print("Your Current Balance: ₹", amt)
logs.append("Checked Balance")
count += 1
# -------- RESET OPERATION COUNT --------
elif operation == 'r':
print("Operation count reset!")
count = 0
logs.append("Operation count reset")
# -------- EXIT SYSTEM --------
elif operation == 'e':
print("\nThank you for using ATM!")
break
else:
print("Invalid Option! Try again.")
# ---------------- SHOW LOG REPORT ----------------
print("\n------ TRANSACTION LOGS ------")
for entry in logs:
print(entry)
print("Final Balance:", amt)
print("Session Ended.")
✔ Improvements Added in This Version
- Fixed indent issues
- Added transaction log system
- Added input validation
- Improved user experience messages
- Modular readable code
- Protected against negative debit
- Case-insensitive operation choices
ATM Flowchart (Conceptual)
Below is the conceptual flow (text version):
Start
│
├── Enter PIN (max 3 attempts)
│ ├── Correct → Continue
│ └── Wrong x3 → Exit
│
├── Show Menu (C/D/B/R/E)
│
├── If C → Credit → Log → Count++
├── If D → Debit → Log → Count++
├── If B → Show Balance → Log → Count++
├── If R → Reset Count
├── If E → Exit & Show Log
│
└── End
OOP Based ATM Program (Extra Content)
Below is an object-oriented version of the ATM program for advanced learners.
class ATM:
def __init__(self, pin, balance=5000):
self.pin = pin
self.balance = balance
self.logs = []
self.count = 0
def verify_pin(self):
for i in range(3):
user_pin = input("Enter PIN: ")
if user_pin == self.pin:
return True
print("Wrong PIN! Attempts left:", 2 - i)
return False
def credit(self):
amount = int(input("Enter amount to credit: "))
self.balance += amount
self.logs.append(f"Credited: {amount}")
print("Amount Credited Successfully!")
def debit(self):
amount = int(input("Enter amount to debit: "))
if amount <= self.balance:
self.balance -= amount
self.logs.append(f"Debited: {amount}")
print("Amount Debited Successfully!")
else:
print("Insufficient Balance!")
def check_balance(self):
print("Current Balance:", self.balance)
self.logs.append("Checked Balance")
def start(self):
if not self.verify_pin():
print("Account Locked!")
return
while self.count < 3:
choice = input("\nC-Credit | D-Debit | B-Balance | E-Exit: ").lower()
if choice == 'c':
self.credit()
elif choice == 'd':
self.debit()
elif choice == 'b':
self.check_balance()
elif choice == 'e':
break
else:
print("Invalid Option!")
self.count += 1
print("\nTransaction Logs:")
for log in self.logs:
print(log)
atm = ATM("1111")
atm.start()
Assignments for Students
- Modify ATM to store multiple user accounts using Dictionary.
- Add option to change PIN securely.
- Store all logs in a text file with date & time.
- Add withdrawal limit per day.
- Create GUI ATM using Tkinter.
Conclusion
This ATM program is a perfect Python mini-project that covers: loops, conditions, strings, functions, OOP, logging, and validation. The enhanced version makes it suitable for classroom teaching, interviews, and practical lab assignments.
2 Comments
PIN=3108
ReplyDeleteb=75000
k=3
flag=False
count=1
log=""
while(k):
p=int(input("Enter PIN : "))
if(PIN==p):
flag=True
break
else:
print("Enter Correct PIN.....")
k-=1
else:
print("Attempt Completed.....")
while(flag and count<=3):
print("Welcome Shivam......")
print("for Credit, press C\ for Debit, press D")
print("for checkBALACE, press B\n for Exit, press E")
print("for Continue, press C")
s=input("what you have to do : ")
if(s=='d' or s=='D'):
putBALANCE=int(input("Enter ammount : "))
log += "DEBIT OPERATION \n"
if putBALANCE<=b:
b-=putBALANCE;
log += "DEBIT AMOUNT IS "+str(b)+" \n"
else:
log += "DEBIT AMOUNT IS Insufficient balance \n"
print("Insufficient balance")
count+=1
elif(s=='c' or s=='C'):
putBALANCE=int(input("Enter ammount : "));
log += "CREDIT OPERATION, Credit amount "+str(putBALANCE)+"\n"
b+=putBALANCE;
count+=1
log += "TOTAL AMOUNT IS "+str(b)+"\n"
elif(s=='b' or s=='B'):
print("Your curret balance is : ",b)
log += "TOTAL BALANCE IS "+str(b)+"\n"
count+=1
elif(s=='e' or s=='E'):
flag=False
elif(s=='c' or s=='C'):
continue;
else:
if c>3:
print("You can only perform three operation")
print(log)
ReplyDeletepin='1111'
flag=False
def processATM(flag):
count=0
amt=5000
if flag:
while(True):
if count>3:
exit(0)
operation = input("""
press c for creadit
press d for debit
press b for check balance
press e for exit and press
r for repeate operation\n:""")
match operation:
case 'd':
debit_amount = int(input("please enter the amount you want to debit:"))
if(debit_amount<amt):
amt = amt-debit_amount
print("now your current balance is ",amt,"and you have debited rupees ",debit_amount)
count = count+1
print(count)
else:
print("no sufficient balance in your account")
case 'c':
credit_amount = int(input("please enter the amount you want to credit:"))
amt = amt+credit_amount
print("now your current balance is ",amt,"and you have credited rupees ",credit_amount)
count = count+1
print(count)
case 'b':
print("your current balance is = ",amt)
count = count+1
print(count)
case "e":
exit(0)
case "r":
count=0
continue
else:
print("you have entered wrong pin code and you complete your attempt")
for i in range(1,4):
pin = input("enter pin code:")
if pin=='1111':
flag=True
break
print("please enter correct pin code\n")
processATM(flag)
sir can you review this code
Thanks
POST Answer of Questions and ASK to Doubt