0% found this document useful (0 votes)
5 views4 pages

Multi-User ATM Program Code

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

Multi-User ATM Program Code

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

ATM Main Code (Multi-User)

# ATM Mechanism - Main Program (Multi-User)

# Uses functions from the source code (they must be in the same folder if separated)

# For submission this file contains the full logic again for simplicity

# User data

users = ["user1", "user2"]

pins = ["1111", "2222"]

balances = [1000.0, 2000.0]

def login():

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 attempts. Exiting.")

return None

else:
print("Invalid username.")

return None

def show_menu():

print("\nATM Menu:")

print("1. Check Balance")

print("2. Deposit")

print("3. Withdraw")

print("4. Exit")

def check_balance(user_index):

print("Your current balance is: ${:.2f}".format(balances[user_index]))

def deposit(user_index):

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(user_index):

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.")

def main():

user_index = login()

if user_index is not None:

while True:

show_menu()

choice = input("Enter your choice: ")

if choice == '1':

check_balance(user_index)

elif choice == '2':

deposit(user_index)

elif choice == '3':

withdraw(user_index)

elif choice == '4':

print("Thank you for using the ATM. Goodbye!")


break

else:

print("Invalid choice. Try again.")

if __name__ == "__main__":

main()

You might also like