Need help with this asap.
Peter Otten
__peter__ at web.de
Tue Jan 12 07:12:43 EST 2016
ifeanyioprah--- via Python-list wrote:
> Create a class called BankAccount
> Create a constructor that takes in an integer and assigns this to a
`balance` property.
> Create a method called `deposit` that takes in cash deposit amount and
updates the balance accordingly.
> Create a method called `withdraw` that takes in cash withdrawal amount and
updates the balance accordingly. if amount is greater than balance return
`"invalid transaction"`
Return or print? You print.
> Create a subclass MinimumBalanceAccount of the BankAccount class.
I would suppose that such a MinimumBalanceAccount needs a way to specify the
minimum balance (in the initializer) and to ensure (both initially and in
the withdraw() method) that the account actually has that minimum balance.
> This was my solution and I still got error. What should I do.
> class BankAccount:
> def __init__(self, initial_amount):
> self.balance = initial_amount
> def deposit(self, amount):
> self.balance += amount
> def withdraw(self, amount):
> if self.balance>= amount:
> self.balance -= amount
> else:
> print('invalid transaction')
> a1 = BankAccount (90)
> a1.deposit(90)
> a1.withdraw(40)
> a1.withdraw(1000)
> class MinimumBalanceAccount(BankAccount):
> def __init__(self):
> BankAccount.__init__(self)
>
More information about the Python-list
mailing list