ATM Source Code (Multi-User)
# ATM Mechanism - Source Code (Multi-User)
# Contains data and functions used by the main program
# User data
users = ["user1", "user2"]
pins = ["1111", "2222"]
balances = [1000.0, 2000.0]
def authenticate_user():
"""Handles user login and returns the index of the authenticated user."""
while True:
username = input("Enter username: ").lower()
if username in users:
user_index = [Link](username)
for _ in range(3):
pin = input("Enter PIN: ")
if pin == pins[user_index]:
print("Welcome,", username)
return user_index
else:
print("Invalid PIN. Try again.")
print("Too many invalid PIN attempts. Account locked.")
return None
else:
print("Invalid username. Try again.")
def show_menu():
"""Displays the ATM menu options."""
print("\nATM Menu:")
print("1. Check Balance")
print("2. Deposit")
print("3. Withdraw")
print("4. Exit")
def check_balance(user_index):
"""Displays the current balance for the given user."""
print("Your current balance is: ${:.2f}".format(balances[user_index]))
def deposit_funds(user_index):
"""Handles depositing funds into the user's account."""
try:
amount = float(input("Enter amount to deposit: $"))
if amount > 0:
balances[user_index] += amount
print("Deposited ${:.2f}. New balance: ${:.2f}".format(amount, balances[user_index]))
else:
print("Deposit amount must be positive.")
except ValueError:
print("Invalid amount.")
def withdraw_funds(user_index):
"""Handles withdrawing funds from the user's account."""
try:
amount = float(input("Enter amount to withdraw: $"))
if amount > 0:
if balances[user_index] >= amount:
balances[user_index] -= amount
print("Withdrew ${:.2f}. New balance: ${:.2f}".format(amount,
balances[user_index]))
else:
print("Insufficient funds.")
else:
print("Withdrawal amount must be positive.")
except ValueError:
print("Invalid amount.")