[sf-lug] [PYCLASS] Still on exercise 2.1

Christian Einfeldt einfeldt at gmail.com
Sun Oct 5 21:27:51 PDT 2008


On Sat, Oct 4, 2008 at 1:02 AM, Jeffrey Malone <ieatlint at tehinterweb.com>wrote:

> Just a couple ideas...
>
> Firstly, to point out two things that may be of interest with the 2.4
> exercise:
> pi = 3.14159
> print ((4/3.0)*pi)*(5**3)
>
> This is not incorrect.  But I figured I'd add that chapter three
> explains why two things could be changed.
> First, python includes a pi constant in the math library, so you don't
> need to define it.  And second, the order of operations in python
> follow what a scientific calculator produces, such that parenthesis
> are useless in this expression:
> import math
> print 4/3.0*math.pi*5**3


I am running python on Gutsy, so maybe I don't have the proper version of
Python, but I do update regularly.  Still, I got these results:

>>> print 4/3.0*math.pi*5**3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'math' is not defined
>>> print 4/3.0*pi*5**3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pi' is not defined
>>>

thx for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://linuxmafia.com/pipermail/sf-lug/attachments/20081005/007c2632/attachment.html>


More information about the sf-lug mailing list