0% found this document useful (0 votes)
7 views2 pages

Aattmm

The document outlines an ATM simulator program that allows users to create accounts, authenticate, and perform transactions such as deposits, withdrawals, and checking their balance. It includes a User class to manage individual user data and an ATMSimulator class to handle user interactions and menu options. The program continuously runs, allowing users to log in and perform various banking operations until they choose to log out or exit.

Uploaded by

sujalswami0304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Aattmm

The document outlines an ATM simulator program that allows users to create accounts, authenticate, and perform transactions such as deposits, withdrawals, and checking their balance. It includes a User class to manage individual user data and an ATMSimulator class to handle user interactions and menu options. The program continuously runs, allowing users to log in and perform various banking operations until they choose to log out or exit.

Uploaded by

sujalswami0304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

class User:

def __init__(self, username, pin):


self.username = username
self.pin = pin
self.balance = 0.0
self.transaction_history = []

def deposit(self, amount):


self.balance += amount
self.transaction_history.append(f"Deposited: ${amount:.2f}")

def withdraw(self, amount):


if amount <= self.balance:
self.balance -= amount
self.transaction_history.append(f"Withdrew: ${amount:.2f}")
return True
else:
return False

def check_balance(self):
return self.balance

def get_transaction_history(self):
return self.transaction_history

class ATMSimulator:
def __init__(self):
self.users = {}
self.current_user = None

def create_account(self):
username = input("Enter a username: ")
pin = input("Enter a 4-digit PIN: ")
if username in self.users:
print("Username already exists. Please choose a different username.")
else:
self.users[username] = User(username, pin)
print("Account created successfully!")

def authenticate_user(self):
username = input("Enter your username: ")
pin = input("Enter your PIN: ")
user = self.users.get(username)
if user and user.pin == pin:
self.current_user = user
print(f"Welcome, {username}!")
else:
print("Invalid username or PIN.")

def display_menu(self):
print("\nATM Menu:")
print("1. Check Balance")
print("2. Deposit Money")
print("3. Withdraw Money")
print("4. Transaction History")
print("5. Logout")

def run(self):
while True:
print("\n1. Create Account")
print("2. Login")
print("3. Exit")
choice = input("Select an option (1-3): ")

if choice == '1':
self.create_account()
elif choice == '2':
self.authenticate_user()
if self.current_user:
while True:
self.display_menu()
option = input("Select an option (1-5): ")

if option == '1':
print(f"Your current balance is: $
{self.current_user.check_balance():.2f}")
elif option == '2':
amount = float(input("Enter amount to deposit: $"))
if amount > 0:
self.current_user.deposit(amount)
print(f"${amount:.2f} has been deposited.")
else:
print("Invalid amount. Please enter a positive
number.")
elif option == '3':
amount = float(input("Enter amount to withdraw: $"))
if amount > 0:
if self.current_user.withdraw(amount):
print(f"${amount:.2f} has been withdrawn.")
else:
print("Insufficient funds.")
else:
print("Invalid amount. Please enter a positive
number.")
elif option == '4':
history = self.current_user.get_transaction_history()
print("Transaction History:")
for transaction in history:
print(transaction)
elif option == '5':
print("Logging out...")
self.current_user = None
break
else:
print("Invalid choice. Please

You might also like