Need help on a project To :"Create a class called BankAccount with the following parameters "

Michael Torrie torriem at gmail.com
Sat Dec 19 20:09:01 EST 2015


On 12/19/2015 05:41 PM, Mark Lawrence wrote:
> On 19/12/2015 23:19, malitician at 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?


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /