🐍 Can be run on Jupyter Notebook
#CLASS OF BANK ACCOUNT
class Account:#STORING OWNER NAME AND BALANCE DATA ON CREATION OF OBJECT
def __init__(self, owner, balance=0):self.owner=owner
self.balance=balance
#RETURNS ACCOUNT INFORMATION ON CALLING THE OBJECT
def __str__(self):return f'Account owner : {self.owner}\nAccount balance : {self.balance}'
#FUNCTION TO DEPOSIT AMOUNT IN ACCOUNT
def deposit(self, dep_amt=0):self.balance+=dep_amt
return f'Successfully deposited {dep_amt}. The balance now is {self.balance}'
#FUNCTION TO WITHDRAW AMOUNT FROM ACCOUNT
def withdraw(self, drw_amt=0):#WORKS ONLY IF THERE IS SUFFICIENT BALANCE
if drw_amt<=self.balance:self.balance-=drw_amt
return f'{drw_amt} withdrawn. Current balance is {self.balance}'
else:
return f'Withdrawal amount greater than balance. Your balance amount is {self.balance}'
Comments
Post a Comment