PYTHON PROJECT 14

Python Bank Account Simulator

Learn how to build a simple banking system using Python variables, functions, conditions, loops and input validation.

1. Project Introduction

A Bank Account Simulator is a beginner-friendly Python project that demonstrates how basic banking operations can be represented in a program.

The program will allow a user to check balance, deposit money, withdraw money and view transactions.

This is an educational simulator. It does not connect to a real bank account or process real financial transactions.

2. Creating the Account Balance

We first need a variable to store the current account balance.

balance = 10000

print(
    "Current Balance:",
    balance
)

3. Creating a PIN

A simple PIN can be used to demonstrate account authentication.

correct_pin = "1234"

4. Taking PIN Input

pin = input(
    "Enter your PIN: "
)

5. Verifying the PIN

The if statement can compare the entered PIN with the stored PIN.

if pin == correct_pin:

    print(
        "Login successful."
    )

else:

    print(
        "Invalid PIN."
    )

6. Creating the Menu

After login, the user can choose a banking operation.

print("1. Check Balance")
print("2. Deposit")
print("3. Withdraw")
print("4. Exit")

7. Using a while Loop

A while loop allows the banking menu to remain active until the user chooses Exit.

while True:

    print("Bank Menu")

    choice = input(
        "Enter choice: "
    )

    if choice == "4":

        break

8. Checking Balance

The current balance can simply be displayed.

if choice == "1":

    print(
        "Balance:",
        balance
    )

9. Depositing Money

Deposit means adding money to the account.

amount = float(
    input(
        "Enter deposit amount: "
    )
)

balance += amount

10. Creating a Deposit Function

A function keeps the banking logic organized.

def deposit(balance):

    amount = float(
        input(
            "Enter deposit amount: "
        )
    )

    if amount > 0:

        balance += amount

        print(
            "Deposit successful."
        )

    else:

        print(
            "Invalid amount."
        )

    return balance

11. Withdrawing Money

Withdrawal removes money from the account. We must make sure that the user cannot withdraw more than the available balance.

amount = float(
    input(
        "Enter withdrawal amount: "
    )
)

if amount <= balance:

    balance -= amount

else:

    print(
        "Insufficient balance."
    )

12. Creating a Withdraw Function

def withdraw(balance):

    amount = float(
        input(
            "Enter withdrawal amount: "
        )
    )

    if amount <= 0:

        print(
            "Invalid amount."
        )

    elif amount > balance:

        print(
            "Insufficient balance."
        )

    else:

        balance -= amount

        print(
            "Withdrawal successful."
        )

    return balance

13. Recording Transactions

A list can store transaction messages.

transactions = []

transactions.append(
    "Deposit: ₹500"
)

transactions.append(
    "Withdrawal: ₹200"
)

14. Viewing Transaction History

for transaction in transactions:

    print(
        transaction
    )

15. Validating Deposit Amount

A deposit should be greater than zero.

if amount <= 0:

    print(
        "Amount must be greater than zero."
    )

16. Validating Withdrawal

A withdrawal must be positive and must not exceed the current balance.

if amount <= 0:

    print(
        "Invalid amount."
    )

elif amount > balance:

    print(
        "Insufficient balance."
    )

17. Handling Invalid Input

float() can raise an error when the user enters text instead of a number. We can use try/except.

try:

    amount = float(
        input(
            "Enter amount: "
        )
    )

except ValueError:

    print(
        "Please enter a valid number."
    )

18. Complete Menu Logic

while True:

    print()
    print("1. Check Balance")
    print("2. Deposit")
    print("3. Withdraw")
    print("4. Transactions")
    print("5. Exit")

    choice = input(
        "Enter choice: "
    )

    if choice == "1":

        print(balance)

    elif choice == "2":

        balance = deposit(
            balance
        )

    elif choice == "3":

        balance = withdraw(
            balance
        )

    elif choice == "4":

        show_transactions()

    elif choice == "5":

        break

    else:

        print(
            "Invalid choice."
        )

19. Complete Project Flow

01 Enter PIN
02 Verify PIN
03 Open Menu
04 Check Balance
05 Deposit
06 Withdraw
07 View Transactions
08 Exit

20. Concepts You Practiced

21. Run Complete Project 🚀

You have now learned the basic logic behind a Python Bank Account Simulator.

Run Complete Project