Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am trying to access the value of pi in Python 2.7, but it seems as if Python doesn't recognize math.pi. I am using IDLE, and when I try to print the value of math.pi, it says that "Math is not defined" or "math is not defined". I can't upgrade to the next version without risk, so is there a way to access pi in Python 2.7? Alternatively, is there another way to convert degrees to radians in Python 2.7 without dealing with Pi?

1 Answer

0 votes
by (106k points)

Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win32 

Type "help", "copyright", "credits" or "license" for more information. 

>>> import math 

>>> math.pi 

3.141592653589793

Check out the Python tutorial on modules and how to use them.

As for the second part of your question, Python comes with batteries included, of course:

>>> math.radians(90) 

1.5707963267948966 

>>> math.radians(180) 

3.141592653589793

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
asked Jan 2, 2021 in Python by ashely (50.2k points)
0 votes
4 answers
0 votes
1 answer

Browse Categories

...