# Automated Teller Machine simulator. # All extras added in (transfers, PIN, etc.) # No significant error-checking, other than for positive values and limits. savings = 0 chequing = 0 print("Welcome to GarvinBank. What would you like to do?") # have the user enter a PIN to access their accounts PIN = 1234 guess = "" fails = 0 while guess != PIN and fails < 3: guess = int(input("Please enter your PIN: ")) if guess != PIN: fails += 1 guess = int(input("Invalid PIN.", 3-fails, "attempts left: ")) # incorrect PIN, lock ATM if fails == 3: print("This account has been locked. Goodbye.") # user successfully logs in else: transactions = "" action = "" while action != "Q" and action != "q": action = input("(D)eposit, (W)ithdraw, (T)ransfer Funds, Show (B)alance, (Q)uit? ") # deposit if action == "D" or action == "d": amount = float(input("How much would you like to deposit? ")) if amount < 0: print("Invalid amount. Must not be negative.") elif amount >= 10000: print("Amount too large. Please see a teller instead.") else: account = input("(C)hequing or (S)avings: ") if account == "C" or account == "c": chequing += amount print("Successfully deposited $"+str(round(amount,2)),"into chequing.") transactions += ("\nDPT CHQ $"+str(round(amount,2))) elif account == "S" or account == "s": savings += amount print("Successfully deposited $"+str(round(amount,2)),"into savings.") transactions += ("\nDPT SAV $"+str(round(amount,2))) else: print("Invalid command.") # withdraw elif action == "W" or action == "w": amount = float(input("How much would you like to withdraw? ")) if amount < 0: print("Invalid amount. Must not be negative.") elif amount >= 10000: print("Amount too large. Please see a teller instead.") else: account = input("(C)hequing or (S)avings: ") if account == "C" or account == "c": if amount > chequing: print("Invalid amount. Cannot exceed balance of $"+str(round(chequing,2))+".") else: chequing -= amount print("Successfully withdrew $"+str(round(amount,2)),"from chequing.") transactions += ("\nWDR CHQ $"+str(round(amount,2))) elif account == "S" or account == "s": if amount > savings: print("Invalid amount. Cannot exceed balance of $"+str(round(savings,2))+".") else: savings -= amount print("Successfully withdrew $"+str(round(amount,2)),"from savings.") transactions += ("\nWDR SAV $"+str(round(amount,2))) else: print("Invalid command.") # transfer funds elif action == "T" or action == "t": amount = float(input("How much would you like to transfer? ")) direction = input("(C)hequing to Savings, or (S)avings to Chequing: ") if direction == "C" or direction == "c": if amount <= chequing: savings += amount chequing -= amount print("Successfully transferred $"+str(round(amount,2)),"from chequing to savings.") transactions += ("\nTRN SAV $"+str(round(amount,2))) elif direction == "S" or direction == "s": if amount <= savings: chequing += amount savings -= amount print("Successfully transferred $"+str(round(amount,2)),"from savings to chequing.") transactions += ("\nTRN CHQ $"+str(round(amount,2))) else: print("Invalid command.") # show balance elif action == "B" or action == "b": account = input("(C)hequing or (S)avings: ") if account == "C" or account == "c": print("The current balance is $"+str(round(chequing,2))+".") transactions += ("\nBAL CHQ") elif account == "S" or account == "s": print("The current balance is $"+str(round(savings,2))+".") transactions += ("\nBAL SAV") else: print("Invalid command.") # bad input elif action != "Q" and action != "q": print("Invalid command. Please enter D, W, B or Q.") # user finished all transactions print("Thank you for banking with GarvinBank.") print("Here is a record of all of your transactions today:", transactions)