Exercise 43. Bank Account class:
- Create a Python class called BankAccount which represents a bank account, having as attributes: accountNumber (numeric type), name (name of the account owner as string type), balance.
- Create a constructor with parameters: accountNumber, name, balance.
- Create a Deposit() method which manages the deposit actions.
- Create a Withdrawal() method which manages withdrawals actions.
- Create an bankFees() method to apply the bank fees with a percentage of 5% of the balance account.
- Create a display() method to display account details.
- Give the complete code for the BankAccount class.
Solution
class BankAccount:
# create the constuctor with parameters: accountNumber, name and balance
def __init__(self,accountNumber, name, balance):
self.accountNumber = accountNumber
self.name = name
self.balance = balance
# create Deposit() method
def Deposit(self , d ):
self.balance = self.balance + d
# create Withdrawal method
def Withdrawal(self , w):
if(self.balance < w):
print("impossible operation! Insufficient balance !")
else:
self.balance = self.balance - w
# create bankFees() method
def bankFees(self):
self.balance = (95/100)*self.balance
# create display() method
def display(self):
print("Account Number : " , self.accountNumber)
print("Account Name : " , self.name)
print("Account Balance : " , self.balance , " $")
# Testing the code :
newAccount = BankAccount(2178514584, "Albert" , 2700)
# Creating Withdrawal Test
newAccount.Withdrawal(300)
# Create deposit test
newAccount.Deposit(200)
# Display account informations
newAccount.display()
The output is :
Account Number : 2178514584
Account Name : Albert
Account Balance : 2600 $
Younes Derfoufi
my-courses.net
my-courses.net
why is it 95/100 it should be 5/100