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:
class BankAccount:
def __init__(self, b):
self.balance = b
def display(self):
print("Balance : "+ str(self.balance))
def withdraw(self, amount):
self.balance -= amount
def deposit(self, amount):
self.balance += amount
In practice:
ba = BankAccount(1000)
ba.deposit(100)
print(ba.balance)
> 1100
Adding conditions:
def withdraw(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"