Class & object-python
Class & object-python
You are tasked with creating a simple BankAccount class to simulate basic banking operations. The
class should have the following features:
1. Attributes:
2. Methods:
o withdraw(self, amount): Deducts the specified amount from the account balance if
sufficient funds are available.
3. Static Method:
Requirements:
1. Create the BankAccount class with the specified attributes and methods.
2. Instantiate at least two objects of the BankAccount class with different account holders and
initial balances.
Example:
class BankAccount:
self.account_holder = account_holder
self.balance = initial_balance
print("Insufficient funds!")
else:
self.balance -= amount
def get_balance(self):
return self.balance
def account_info(self):
@staticmethod
def bank_info():
# Performing transactions
account1.deposit(1000)
account1.withdraw(1500)
account1.account_info()
account2.deposit(2000)
account2.withdraw(500)
account2.account_info()
BankAccount.bank_info()
Expected Output:
Explanation:
1. Class Definition: The BankAccount class is defined with the required attributes and methods.
2. Static Method: The bank_info() static method provides general information about the bank.
3. Object Creation: Two instances of the BankAccount class are created with different account
holders and initial balances.
5. Information Display: The account information and current balance are printed, and the static
method is used to print the bank information.