MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / Bank

Class Bank

projects/Python Banking System/Banking.py:4–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2
3
4class Bank:
5 def __init__(self):
6 """
7 Initializes a Bank object with dictionaries to store user accounts and transaction history.
8 """
9 self.accounts = {} # Dictionary to store user accounts
10 self.transactions = {} # Dictionary to store transaction history
11
12 def create_account(self, account_holder, initial_balance):
13 """
14 Creates a new bank account for a user.
15
16 Args:
17 account_holder (str): The name of the account holder.
18 initial_balance (float): The initial balance for the account.
19
20 Returns:
21 BankAccount: The created BankAccount object.
22 """
23 account_number = self.generate_account_number()
24 account = BankAccount(account_number, account_holder, initial_balance)
25 self.accounts[account_number] = account
26 self.transactions[account_number] = []
27 return account
28
29 def generate_account_number(self):
30 """
31 Generates a random 8-digit account number.
32
33 Returns:
34 str: The generated account number.
35 """
36 return "".join(random.choice("0123456789") for _ in range(8))
37
38 def get_account(self, account_number):
39 """
40 Retrieves a BankAccount object based on the account number.
41
42 Args:
43 account_number (str): The account number to look up.
44
45 Returns:
46 BankAccount: The BankAccount object if found, else None.
47 """
48 return self.accounts.get(account_number)
49
50 def perform_transaction(self, account_number, transaction_type, amount):
51 """
52 Performs a transaction (deposit or withdrawal) on a user's account.
53
54 Args:
55 account_number (str): The account number for the transaction.
56 transaction_type (str): The type of transaction (deposit or withdraw).
57 amount (float): The transaction amount.
58
59 Returns:
60 str: A message indicating the result of the transaction.
61 """

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected