On 2013-09-07 17:02, Byron Ruffin 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

The error message is pretty clear, "ceil" is not defined. If you started by
using "import math", this is expected, because you need to explicitly call
"math.ceil", not just "ceil". If you want to import ceil into your current
namespace, you need to use "from":

    >>> from math import ceil
    >>> ceil(3.14)
    4

Attachment: pgp0TCLXzzsD9.pgp
Description: PGP signature

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to