How do I extend my Python cash machine program to handle multiple accounts?
14:53 03 Feb 2026

I have made a Python function that simulates a cash withdrawal from an ATM, checking for the correct PIN and sufficient balance before processing.

I have defined a function called cash_machine with parameters for the PIN entered and the withdrawal amount. It verifies the PIN and ensures the balance is sufficient before allowing a withdrawal, updating the balance and providing appropriate messages for each scenario.

However, I'm struggling to extend the function to handle multiple accounts (Each account can be represented as a dictionary with keys for account_number, PIN, and balance), add a feature to allow users to change their PIN through the ATM, keeping a log of all transactions for each account, including withdrawals and PIN changes, implementing a daily withdrawal limit for each account, adding comprehensive error handling to manage incorrect inputs and potential security breaches (like repeated incorrect PIN entries) and including administrative functionalities, such as adding new accounts, loading money into the ATM, and viewing machine status.

Here's my code so far:

pin = 4352
withdrawal_amount = 10


def cash_machine(pin, withdrawal_amount):
    global attempts
    attempts = 0
    def pin_func():
        pin = input("Please enter your PIN: ")
        if pin == "4352":
            print("PIN accepted")
            balance_func()
        else:
            print("This is the incorrect PIN.")
            global attempts
            attempts += 1
            if attempts  >= 3:
                print("We have seised your card for security reasons \nHave a lovely day.")
            else:
                pin_func()
    def balance_func():
        global balance, withdrawal_amount
        balance = 10000
        withdrawal_amount = input("How much money would you like to withdraw?\n")
        if int(withdrawal_amount) <= balance:
            print("Accessing account...")
            withdraw_func()
        else:
            print("Insufficient funds!")
            balance_func() 
    def withdraw_func():
        global balance, withdrawal_amount
        new_balance = balance - int(withdrawal_amount)
        print(f"Please take your money and don't forget your card.\nYou're remaining balance is {new_balance}")
    pin_func()
cash_machine(4352, 10)

Can anyone help with my code, please?

python function if-statement global