[Tutor] cs student needs help import math
Amit Saha
amitsaha.in at gmail.com
Sun Sep 8 02:16:10 CEST 2013
On Sun, Sep 8, 2013 at 8:02 AM, Byron Ruffin
<byron.ruffin at g.austincc.edu> wrote:
> I am writing a simple program based off an ipo chart that I did correctly.
> I need to use ceil but I keep getting an error saying ceil is not defined.
> I did import math, I think. I am using 3.2.3 and I imported this way...
>
>>>> import math
>>>> math.pi
> 3.141592653589793
>>>> math.ceil(math.pi)
> 4
>>>> math.floor(math.pi)
> 3
>
> ... but I get the error when using ceil...
>
> pepsticks = ceil(peplength / StickLength)
> Traceback (most recent call last):
> File "<pyshell#19>", line 1, in <module>
> pepsticks = ceil(peplength / StickLength)
> NameError: name 'ceil' is not defined
So, like you see earlier, you used math.ceil() to refer to the ceil()
function. That is how you refer to a function defined in a module.
If you want to refer to it as ceil(), you have to import it like so:
from math import ceil
Best,
Amit.
--
http://echorand.me
More information about the Tutor
mailing list