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

malitician at gmail.com malitician at gmail.com
Sat Dec 26 04:01:18 EST 2015


On Thursday, December 24, 2015 at 9:58:54 PM UTC+1, Tim Chase wrote:
> On 2015-12-24 11:36, malitician at gmail.com wrote:
> > it is a homework, but we are to figure out the solution first , all
> > we need is some guidance please and not to be spoon fed like many
> > thought 
> 
> Ah, with the intended interface as given by the tests, and the code
> you've already put together, you'll find comp.lang.python is a much
> friendlier place.
> 
> 
> >   def test_invalid_operation(self):
> >     self.assertEqual(self.my_account.withdraw(1000), "invalid
> > transaction", msg='Invalid transaction') 
> 
> The test above is failing because your withdraw() method doesn't
> return "invalid transaction" but rather prints it:
> 
> >     def withdraw(self, amount):
> >         if self.balance>= amount:
> >             self.balance  -=  amount
> >         else:
> >           print('invalid transaction')
> 
> as gleaned from this error message:
> 
> > [{"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.000080"}}
> 
> The test says "I expected that calling the function would return
> "invalid transaction" but it didn't" (a better test-runner would
> also have let you know that it had returned None)
> 
> Though frankly, I'd consider that a bad test, since it's an
> exceptional condition, so it should be checking that a custom
> InvalidTransactionException was raised.  But sometimes you have to
> work with what you've got.
> 
> -tkc

you and others here saved my days , instead of "RETURN" i have been using "PRINT". i never knew the differences earlier . Problem solved , thanks for having guys like all of you here. I'm just a week old into python programming and i have learned a lot   .Merry xmas



More information about the Python-list mailing list