Python program to add accounts in a bank (Bank Management System)

Here, we will see a Python program for bank management system to add accounts and get their information.
Submitted by Shivang Yadav, on February 13, 2021

Problem Statement: Create a Python program to add accounts in a bank and get the information of all accounts in the bank.

Here, we will write a Python program that will take input from the user about details of the new account in the bank. And then print the information of each account and the total amount in the bank.

Steps to create the bank management system:

  • Step 1: Create a class named Bank that will store all the information and have methods to get and display account and balance details.
  • Step 2: Method: OpenAccount() takes account information form the user and feeds it to the object.
  • Step 3: Method: ShowAccount(), prints the account information.
  • Step 4: we will create objects of this class and get information. For multiple objects, we will store them into a data structure for reference.

Python Program to add accounts in a bank

class Bank:
    bankbalance=0
    def OpenAccount(self):
        self.__acno=input("Enter Account Number: ")
        self.__name = input("Enter Name: ")
        self.__balance =int(input("Enter Balance: "))
        Bank.bankbalance=Bank.bankbalance+self.__balance

        return self.__acno
 
    def ShowAccount(self):
        print("Account info: ", self.__acno,self.__name, self.__balance)

    @staticmethod
    def ShowBankBalance():
        print("Total Balance: ",Bank.bankbalance)
 
    @classmethod
    def ShowBankBal(cls):
        print("Total Balance: ", cls.bankbalance)

LC=dict()

while(True):
   newAccount =Bank()
   key = newAccount.OpenAccount()
   LC.setdefault(key,newAccount)
   ch=input("Add More y/n? ")
   if(ch=="n"):break

for newAccount in LC.values():
    newAccount.ShowAccount()
    
Bank.ShowBankBalance()
Bank.ShowBankBal()

Output:

Enter Account Number: 101
Enter Name: Prem
Enter Balance: 10000
Add More y/n? y
Enter Account Number: 102
Enter Name: Shivang
Enter Balance: 20000
Add More y/n? y
Enter Account Number: 103
Enter Name: Mini
Enter Balance: 35000
Add More y/n? n
Account info:  103 Mini 35000
Account info:  101 Prem 10000
Account info:  102 Shivang 20000
Total Balance:  65000
Total Balance:  65000

Python class & object programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.