On 20/12/2015 01:09, Michael Torrie wrote:
On 12/19/2015 05:41 PM, Mark Lawrence wrote:
On 19/12/2015 23:19, malitic...@gmail.com wrote:
you are absolutely correct Mark
i'm a beginner in python and from the original question and test case given
above i wrote this
class BankAccount(object):
def __init__(self, initial_balance=0):
self.balance = initial_balance
def deposit(self, amount):
self.balance +=amount
def withdraw(self, amount):
self.balance -= amount
my_account = BankAccount(90)
my_account.withdraw(1000)
if my_account.balance < 4:
print('invalid transaction')
^^^^^^^^^^^^^^^^^^
This code probably belongs in the withdraw() method.
class MinimumBalanceAccount(BankAccount):
def __init__(self, MinimumBalance=4):
self.minbalance = MinimumBalance
after executing this i got this TEST SOLUTION ERROR which i don't know what it
means
{"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.000065"}}
-910
invalid transaction
SO please what is wrong with my code, does it not meet the requirement of the "test
case" given above in the question?
Thanks in advance
It's a start but you've still left things out. If I run your code as
given above it outputs "invalid transaction", exactly as expected. So
how are you running the code? Where does the extra output you give
above come from, presumably the "test case", whatever that might be?
While the output is as we'd expect, the program's logic is probably
wrong. Would not you want to put that logic in the withdraw method to
prevent an invalid transaction?
Frankly I've no idea on the grounds that I simply cannot be bothered to
look, and at this time of the night/early morning I'm not inclined to
play guessing games. Perhaps the OP would be kind enough to provide the
requirements and his/her code in one hit, the answer can be one hit, and
we happily move on to Boxing day.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
--
https://mail.python.org/mailman/listinfo/python-list