class ATM:
def __init__(self):
# Initialize the ATM with a default account and PIN
self.accounts = {
'123456': {'pin': '0000', 'balance': 1000, 'history': []}
self.current_account = None
def authenticate(self, account_number, pin):
"""Authenticate the user based on account number and PIN."""
account = self.accounts.get(account_number)
if account and account['pin'] == pin:
self.current_account = account_number
return True
return False
def account_balance_inquiry(self):
"""Return the account balance of the currently logged-in account."""
if self.current_account:
return self.accounts[self.current_account]['balance']
return "No account is logged in."
def cash_withdrawal(self, amount):
"""Process cash withdrawal for the currently logged-in account."""
if self.current_account:
account = self.accounts[self.current_account]
if amount <= account['balance']:
account['balance'] -= amount
account['history'].append(f"Withdrew ${amount}")
return f"Withdrawal successful. New balance: ${account['balance']}"
else:
return "Insufficient funds."
return "No account is logged in."
def cash_deposit(self, amount):
"""Process cash deposit for the currently logged-in account."""
if self.current_account:
account = self.accounts[self.current_account]
account['balance'] += amount
account['history'].append(f"Deposited ${amount}")
return f"Deposit successful. New balance: ${account['balance']}"
return "No account is logged in."
def pin_change(self, old_pin, new_pin):
"""Change the PIN for the currently logged-in account."""
if self.current_account:
account = self.accounts[self.current_account]
if account['pin'] == old_pin:
account['pin'] = new_pin
account['history'].append("Changed PIN")
return "PIN change successful."
else:
return "Incorrect old PIN."
return "No account is logged in."
def transaction_history(self):
"""Return the transaction history of the currently logged-in account."""
if self.current_account:
return self.accounts[self.current_account]['history']
return "No account is logged in."
def main():
atm = ATM()
print("Welcome to the ATM Simulation")
while True:
print("\n1. Login")
print("2. Exit")
choice = input("Enter choice: ")
if choice == '1':
account_number = input("Enter account number: ")
pin = input("Enter PIN: ")
if atm.authenticate(account_number, pin):
print("Login successful!")
while True:
print("\nATM Menu:")
print("1. Account Balance Inquiry")
print("2. Cash Withdrawal")
print("3. Cash Deposit")
print("4. PIN Change")
print("5. Transaction History")
print("6. Logout")
action = input("Enter action number: ")
if action == '1':
print(f"Your balance is: ${atm.account_balance_inquiry()}")
elif action == '2':
amount = float(input("Enter amount to withdraw: "))
print(atm.cash_withdrawal(amount))
elif action == '3':
amount = float(input("Enter amount to deposit: "))
print(atm.cash_deposit(amount))
elif action == '4':
old_pin = input("Enter old PIN: ")
new_pin = input("Enter new PIN: ")
print(atm.pin_change(old_pin, new_pin))
elif action == '5':
history = atm.transaction_history()
print("Transaction History:")
for record in history:
print(record)
elif action == '6':
print("Logging out...")
atm.current_account = None
break
else:
print("Invalid choice. Please try again.")
else:
print("Authentication failed. Please check your account number and PIN.")
elif choice == '2':
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()