[Tutor] math (pkg) in Jupyter Notebook

Alan Gauld alan.gauld at yahoo.co.uk
Sun Mar 8 05:21:23 EDT 2020


On 08/03/2020 05:20, loomer at gmx.com wrote:

> The math package is installed somewhere on my PC because when I try it
> in an Anaconda terminal, I get...
> 
>      >>> math.pi
>      3.141592653589793

So I'm guessing anaconda automatically imports the math package for you.
(I don't use it so don't know for sure).

> But when I try to run that in a python3 Jupyter Notebook, I get...
> 
>      NameError                      Traceback (most recent call last)
>      <ipython-input-1-c49acc181da4> in <module>
>      ----> 1 math.pi
> 
>      NameError: name 'math' is not defined

You normally (in vanilla python) have to import any module before using
it. So you need:

>>> import math
>>> math.pi

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list