Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106386 > unrolled thread

Re: i cant seem to figure out the error

Started byMRAB <python@mrabarnett.plus.com>
First post2016-04-03 19:21 +0100
Last post2016-04-03 19:21 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: i cant seem to figure out the error MRAB <python@mrabarnett.plus.com> - 2016-04-03 19:21 +0100

#106386 — Re: i cant seem to figure out the error

FromMRAB <python@mrabarnett.plus.com>
Date2016-04-03 19:21 +0100
SubjectRe: i cant seem to figure out the error
Message-ID<mailman.406.1459707718.28225.python-list@python.org>
On 2016-04-03 18:34, Jason Friedman wrote:
>>
>>    - 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"`
>>
>>   def withdraw(self, amount):
>>     self.amount=amount
>>     if(amount > self.balance):
>>       return ("Amount greater than available balance.")
>>     else:
>>   self.balance -= amount
>>     return self.balance
>>
>
> The instructions say to "return 'invalid transaction'" but I expect they
> really want that error printed to STDERR (typically your screen) rather
> than literally returned.  Try this:
>
>    def withdraw(self, amount):
>      self.amount=amount
>      if(amount > self.balance):
>        print "Amount greater than available balance, no funds withdrawn."
>      else:
>        self.balance -= amount
>      return self.balance
>
The instructions say "return", not "print" and the report contains:

self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", 
msg='Invalid transaction')

so it _is_ checking the returned result of 'withdraw'.

Not Pythonic (neither is printing to stderr! :-)), but that's something 
that can be worked on later.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web