Creating Functions That Take Into Account Deposit And Withdrawl
My Program at the moment gives out a balance for a class Bank Account, which in the scenario is chosen to be 1000. However, I want my program to take into account this scenario. ac
Solution 1:
Here is a basic example you could expand off of:
classBankAccount:def__init__(self, b):
self.balance = b
defdisplay(self):
print("Balance : "+ str(self.balance))
defwithdraw(self, amount):
self.balance -= amount
defdeposit(self, amount):
self.balance += amount
In practice:
ba = BankAccount(1000)
ba.deposit(100)
print(ba.balance)
> 1100
Adding conditions:
defwithdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
else:
print("You can't withdraw more than your balance.")
Post a Comment for "Creating Functions That Take Into Account Deposit And Withdrawl"