Bank Management System using Python​

Introduction

This Python project is a simple Bank Management System that simulates creating and managing bank accounts. It allows users to create accounts, deposit or withdraw funds, and check their balance. The project also demonstrates the use of Object-Oriented Programming (OOP) concepts like classes, methods, and instance variables.

Prerequisites

Before starting this project, ensure you have a basic understanding of the following concepts:

  • Python fundamentals (variables, loops, conditionals)
  • Object-Oriented Programming (classes, objects, methods)
  • Input and output in Python
  • Python’s random module for generating account numbers

Learning Objectives

By the end of this project, you will:

  • Understand how to implement a basic bank system using Python.
  • Learn how to use classes and objects to manage users and their accounts.
  • Implement simple authentication for users.
  • Develop skills to handle deposits, withdrawals, and balance checks.

Installation Guide

To run this project, you need:

  1. Python 3.x installed on your system. You can download it from Python’s official website.
  2. Any text editor or integrated development environment (IDE) like Visual Studio Code, PyCharm, or Jupyter Notebooks.

Project Steps

  1. Bank Class: This class manages the bank’s data, including client information and authentication.
  2. Client Class: This class holds information about individual clients, such as their name, account number, and balance.
  3. Main Function: Contains the interactive menu for users to create accounts, deposit, withdraw, or check balance.

Code

				
					import random

class Bank():
    Bname = "Renaissance Bank"
    clients = []
    
    def updateUser(self, client):
        self.clients.append(client)
    
    def authenticate(self, name, account_number, password):
        auth = False
        for i in self.clients:
            if (i.account["name"] == name and 
                i.account["accno"] == account_number and 
                i.account["password"] == password):
                auth = True
                return i
        print("Wrong credentials")
        return False
            
class Client():
    account = {}
    
    def __init__(self, name, deposit, password):
        self.account["name"] = name
        self.account["deposit"] = deposit
        self.account["accno"] = random.randint(100000, 999999)
        self.account["password"] = password
        print(f"Your account has been created, account number is: {self.account['accno']}")
    
    def deposit(self, amnt):
        self.account["deposit"] += amnt
        print("Deposit successful")
    
    def withdraw(self, amnt):
        if self.account["deposit"] >= amnt:
            self.account["deposit"] -= amnt
            print("Withdrawal successful")
        else:
            print("Insufficient funds")
    
    def check(self):
        print(f"Balance: {self.account['deposit']} rupees")

def main():
    bank = Bank()
    print(f"Hello and welcome to {bank.Bname}")
    flag = True
    while flag:
        print("""What would you like to do:
                1.) Create a new account
                2.) Inquire existing account
                3.) Exit""")
        choice = int(input("Press 1, 2, or 3: "))
        if choice == 1:
            name = input("Enter name: ")
            deposit = int(input("Enter deposit amount: "))
            password = input("Enter password: ")
            client = Client(name, deposit, password)
            bank.updateUser(client)
        elif choice == 2:
            name = input("Enter name: ")
            account_number = int(input("Enter account number: "))
            password = input("Enter password: ")
            current_client = bank.authenticate(name, account_number, password)
            if current_client:
                print("""What would you like to do:
                        1.) Deposit
                        2.) Withdraw
                        3.) Check balance
                        4.) Exit""")
                choice = int(input("Press 1, 2, 3, or 4: "))
                if choice == 1:
                    amount = int(input("Enter deposit amount: "))
                    current_client.deposit(amount)
                elif choice == 2:
                    amount = int(input("Enter withdrawal amount: "))
                    current_client.withdraw(amount)
                elif choice == 3:
                    current_client.check()
                else:
                    print("Thank you for visiting")
            else:
                print("Authentication failed")
        else:
            flag = False
    print("Thank you")
    return "Bye"

if __name__ == "__main__":
    main()

				
			

Code

				
					import random

class Bank():
    Bname = "Renaissance Bank"
    clients = []
    
    def updateUser(self, client):
        self.clients.append(client)
    
    def authenticate(self, name, account_number, password):
        auth = False
        for i in self.clients:
            if (i.account["name"] == name and 
                i.account["accno"] == account_number and 
                i.account["password"] == password):
                auth = True
                return i
        print("Wrong credentials")
        return False
            
class Client():
    account = {}
    
    def __init__(self, name, deposit, password):
        self.account["name"] = name
        self.account["deposit"] = deposit
        self.account["accno"] = random.randint(100000, 999999)
        self.account["password"] = password
        print(f"Your account has been created, account number is: {self.account['accno']}")
    
    def deposit(self, amnt):
        self.account["deposit"] += amnt
        print("Deposit successful")
    
    def withdraw(self, amnt):
        if self.account["deposit"] >= amnt:
            self.account["deposit"] -= amnt
            print("Withdrawal successful")
        else:
            print("Insufficient funds")
    
    def check(self):
        print(f"Balance: {self.account['deposit']} rupees")

def main():
    bank = Bank()
    print(f"Hello and welcome to {bank.Bname}")
    flag = True
    while flag:
        print("""What would you like to do:
                1.) Create a new account
                2.) Inquire existing account
                3.) Exit""")
        choice = int(input("Press 1, 2, or 3: "))
        if choice == 1:
            name = input("Enter name: ")
            deposit = int(input("Enter deposit amount: "))
            password = input("Enter password: ")
            client = Client(name, deposit, password)
            bank.updateUser(client)
        elif choice == 2:
            name = input("Enter name: ")
            account_number = int(input("Enter account number: "))
            password = input("Enter password: ")
            current_client = bank.authenticate(name, account_number, password)
            if current_client:
                print("""What would you like to do:
                        1.) Deposit
                        2.) Withdraw
                        3.) Check balance
                        4.) Exit""")
                choice = int(input("Press 1, 2, 3, or 4: "))
                if choice == 1:
                    amount = int(input("Enter deposit amount: "))
                    current_client.deposit(amount)
                elif choice == 2:
                    amount = int(input("Enter withdrawal amount: "))
                    current_client.withdraw(amount)
                elif choice == 3:
                    current_client.check()
                else:
                    print("Thank you for visiting")
            else:
                print("Authentication failed")
        else:
            flag = False
    print("Thank you")
    return "Bye"

if __name__ == "__main__":
    main()

				
			

Pseudo Code explaining this Python Project

				
					1.	Initialize a Bank class to store bank name and client data.
2.	Create a Client class to manage each client’s information.
3.	In the main() function, create an interactive menu that asks the user to:
o	Create a new account: This will prompt the user for name, deposit, and password and create a client object.
o	Inquire an existing account: This allows the user to deposit, withdraw, or check balance.
4.	For each action, authenticate the user by comparing their credentials.

				
			

Pseudo Code explaining this Python Project

				
					1.	Initialize a Bank class to store bank name and client data.
2.	Create a Client class to manage each client’s information.
3.	In the main() function, create an interactive menu that asks the user to:
o	Create a new account: This will prompt the user for name, deposit, and password and create a client object.
o	Inquire an existing account: This allows the user to deposit, withdraw, or check balance.
4.	For each action, authenticate the user by comparing their credentials.

				
			

Code Explanation

  • The Bank class holds the bank’s data (clients, bank name) and contains methods to update the list of clients and authenticate users based on their name, account number, and password.
  • The Client class holds individual client details such as account number, balance, and password. It also has methods to deposit, withdraw, and check the balance.
  • The main() function is the driver code that provides a menu interface for the user to interact with the system.

Challenges and Solutions

  • Challenge: Generating unique account numbers.
    • Solution: The random.randint(100000, 999999) function generates random account numbers within a range.
  • Challenge: Validating user authentication.
    • Solution: The authenticate() method compares the input credentials with the stored client data. If credentials match, the user is authenticated.

Testing

  • Create multiple accounts with different names and passwords to ensure account creation is working.
  • Test deposits and withdrawals to confirm the balance is updated correctly.
  • Try entering incorrect credentials during authentication to test the error handling for wrong passwords or account numbers.

Additional Resources

FAQs

  1. What happens if I enter incorrect credentials?
    • The system will print “Wrong credentials” and prompt you to try again.
  2. Can I withdraw more than the available balance?
    • No, the system checks the balance before allowing withdrawals. If you try to withdraw more than the available amount, it will print “Insufficient funds.”
  3. Is the account number unique?
    • Account numbers are randomly generated using Python’s random.randint() function, so while it’s unlikely, duplicates can theoretically occur.

Project by Parn Jain, Team edSlash.