CODE:
from datetime import datetime
class ATM:
def __init__(self):
self.pin = None
self.balance = 5000
def set_pin(self):
while True:
pin = input("Set a 4-digit ATM PIN: ")
if len(pin) == 4 and pin.isdigit():
self.pin = pin
print("PIN set successfully!")
break
else:
print("Invalid PIN. Please enter a 4-digit number.")
def verify_pin(self):
attempts = 3
while attempts > 0:
entered_pin = input("Enter your 4-digit ATM PIN: ")
if entered_pin == self.pin:
print("PIN verified successfully.")
return True
else:
attempts -= 1
print(f"Incorrect PIN. You have {attempts} attempts left.")
print("Too many incorrect attempts. Exiting.")
return False
def show_balance(self):
print("Your current balance is:", self.balance)
def withdraw(self):
amount = int(input("Enter the amount to withdraw: "))
if 0 < amount <= self.balance:
self.balance -= amount
print("Amount withdrawn successfully.")
self.generate_bill(amount)
elif amount > self.balance:
print("Insufficient funds.")
else:
print("Invalid withdrawal amount.")
def generate_bill(self, amount):
current_time = datetime.now().strftime("%d-%m-%y %H:%M:%S")
print("\n***Transaction Receipt***")
print(f"Date and Time: {current_time}")
print(f"Withdrawn Amount: {amount}")
print(f"Remaining Balance: {self.balance}")
print("Thank you! Visit again.")
print("********************")
def main():
atm = ATM()
print("\nWelcome to the IOB ATM!")
atm.set_pin()
while True:
print("\n***Welcome to the IOB ATM***")
print("1. Check Balance")
print("2. Withdraw")
print("3. Exit")
choice = input("Enter your choice: ")
if choice in ['1', '2']:
if atm.verify_pin():
if choice == '1':
atm.show_balance()
elif choice == '2':
atm.withdraw()
elif choice == '3':
print("Thank you for using the ATM.")
break
else:
print("Invalid choice")
if __name__ == "__main__":
main()