Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106373 > unrolled thread
| Started by | anthony uwaifo <anthony.uwaifo55@gmail.com> |
|---|---|
| First post | 2016-04-03 16:06 +0100 |
| Last post | 2016-04-03 18:18 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
i cant seem to figure out the error anthony uwaifo <anthony.uwaifo55@gmail.com> - 2016-04-03 16:06 +0100
Re: i cant seem to figure out the error Peter Pearson <pkpearson@nowhere.invalid> - 2016-04-03 18:18 +0000
| From | anthony uwaifo <anthony.uwaifo55@gmail.com> |
|---|---|
| Date | 2016-04-03 16:06 +0100 |
| Subject | i cant seem to figure out the error |
| Message-ID | <mailman.397.1459700384.28225.python-list@python.org> |
hi everyone,
please i need help with this assignment. I have written a code and i still
get an error. please help me debug my code.
instructions:
- 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"`
- Create a subclass MinimumBalanceAccount of the BankAccount class
My code:
class BankAccount(object):
def __init__(self, balance):
self.balance = balance
def deposit(self, amount):
self.amount=amount
self.balance += amount
return self.balance
def withdraw(self, amount):
self.amount=amount
if(amount > self.balance):
return ("Amount greater than available balance.")
else:
self.balance -= amount
return self.balance
class MinimumBalanceAccount(BankAccount):
def __init__(self, minimum_balance):
BankAccount.__init__(self)
self.minimum_balance = minimum_balance
act = BankAccount(5)
act.deposit(400)
act.withdraw(200)
print act.balance
error message:
THERE IS AN ERROR/BUG IN YOUR CODE*Results: *
{"finished": true, "success": [{"fullName": "test_balance",
"passedSpecNumber": 1}, {"fullName": "test_deposit",
"passedSpecNumber": 2}, {"fullName": "test_sub_class",
"passedSpecNumber": 3}, {"fullName": "test_withdraw",
"passedSpecNumber": 4}], "passed": false, "started": true, "failures":
[{"failedSpecNumber": 1, "fullName": "test_invalid_operation",
"failedExpectations": [{"message": "Failure in line 23, in
test_invalid_operation\n
self.assertEqual(self.my_account.withdraw(1000), \"invalid
transaction\", msg='Invalid transaction')\nAssertionError: Invalid
transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time":
"0.000079"}}
205
[toc] | [next] | [standalone]
| From | Peter Pearson <pkpearson@nowhere.invalid> |
|---|---|
| Date | 2016-04-03 18:18 +0000 |
| Message-ID | <dmd531F7441U1@mid.individual.net> |
| In reply to | #106373 |
On Sun, 3 Apr 2016 16:06:58 +0100, anthony uwaifo wrote:
[snip]
>
> class BankAccount(object):
> def __init__(self, balance):
> self.balance = balance
>
>
> def deposit(self, amount):
> self.amount=amount
> self.balance += amount
> return self.balance
>
>
> def withdraw(self, amount):
> self.amount=amount
> if(amount > self.balance):
> return ("Amount greater than available balance.")
> else:
> self.balance -= amount
> return self.balance
>
>
>
> class MinimumBalanceAccount(BankAccount):
> def __init__(self, minimum_balance):
> BankAccount.__init__(self)
> self.minimum_balance = minimum_balance
>
> act = BankAccount(5)
> act.deposit(400)
> act.withdraw(200)
> print act.balance
There is an indentation error following the "else:" line. After
I fixed that, the program runs and prints "205" (under Python 2.7.3).
--
To email me, substitute nowhere->runbox, invalid->com.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web