[Tutor] Calculating a math formula and finding errors
Bob Gailer
ramrom@earthling.net
Tue Jan 14 11:43:04 2003
--=======652C444A=======
Content-Type: multipart/alternative; x-avg-checked=avg-ok-3DBD71BC; boundary="=====================_3886538==.ALT"
--=====================_3886538==.ALT
Content-Type: text/plain; x-avg-checked=avg-ok-3DBD71BC; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit
At 03:51 PM 1/14/2003 +0100, Jens Kubieziel wrote:
> def factorial(z):
> assert z >= 0, "Invalid input: z must be nonnegative."
>Where can I find some information what this exactly does?
From the Language Reference:
6.2 Assert statements
Assert statements are a convenient way to insert debugging assertions into
a program:
assert_statement ::= "assert" <Booleans.htm#tok-expression>expression
["," <Booleans.htm#tok-expression>expression]
The simple form, "assert expression", is equivalent to:
if __debug__:
if not expression: raise AssertionError
>Now this function _always_ raises an exception. And I'm a bit perplex ...
It should raise the exception only for z < 0. That's how it works when I
test it.
Bob Gailer
mailto:ramrom@earthling.net
303 442 2625
--=====================_3886538==.ALT
Content-Type: text/html; x-avg-checked=avg-ok-3DBD71BC; charset=us-ascii
Content-Transfer-Encoding: 8bit
<html>
<body>
At 03:51 PM 1/14/2003 +0100, Jens Kubieziel wrote:<br><br>
<blockquote type=cite class=cite cite> def factorial(z):<br>
assert z >= 0, "Invalid input: z must be
nonnegative."<br>
Where can I find some information what this exactly does?
</blockquote><br>
From the Language Reference:<br><br>
<h1><b>6.2 Assert statements </b></h1>Assert
statements<a name="l2h-306"></a> are a convenient way to insert debugging
assertions<a name="l2h-307"></a> into a program:
<dl>
<dd><a name="tok-assert_statement"></a>assert_statement ::=
"assert" <a href="Booleans.htm#tok-expression">expression</a>
["," <a href="Booleans.htm#tok-expression">expression</a>]
</dl>The simple form, "<tt>assert expression</tt>", is
equivalent to:
<dl>
<dd><pre>if __debug__:
<dd> if not expression: raise AssertionError
</pre><blockquote type=cite class=cite cite>
</dl>Now this function _always_ raises an exception. And I'm a bit
perplex ...</blockquote><br>
It should raise the exception only for z < 0. That's how it works when
I test it.<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
<a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a><br>
303 442 2625<br>
</body>
</html>
--=====================_3886538==.ALT--
--=======652C444A=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-3DBD71BC
Content-Disposition: inline
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.438 / Virus Database: 246 - Release Date: 1/7/2003
--=======652C444A=======--