Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101535
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Need help with this asap. |
| Date | 2016-01-12 13:12 +0100 |
| Organization | None |
| Message-ID | <mailman.54.1452600779.13488.python-list@python.org> (permalink) |
| References | <1452577684.494943577@f402.i.mail.ru> |
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)
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Need help with this asap. Peter Otten <__peter__@web.de> - 2016-01-12 13:12 +0100
csiph-web