[Tutor] Error Checking/Defensive Programming
Steve Willoughby
steve at alchemy.com
Thu Jan 26 04:54:22 CET 2012
On 25-Jan-12 19:49, Devin Jeanpierre wrote:
> On Wed, Jan 25, 2012 at 10:36 PM, Michael Lewis<mjolewis at gmail.com> wrote:
>> if number>=0 or< 0:
As long as we're helping with this, I'll just add a comment about this
conditional statement. First, if you string together two expressions
with "or" between them, they must each be complete statements.
number>=0 makes sense, but what does <0 mean? You'd really write it as
if number >= 0 or number < 0:
However, that doesn't make sense because if "number" is something that
can be compared with integers like 0, it will either be >= 0 or < 0, so
the condition will always be true. If "number" contains something that
doesn't make sense to compare like that, then it just won't work (i.e.,
it'll likely throw an exception). (usually :)
--
Steve Willoughby / steve at alchemy.com
"A ship in harbor is safe, but that is not what ships are built for."
PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C
More information about the Tutor
mailing list