Python : name 'math' is not defined Error?

You need to import math rather than from math import *.


You did a mistake..

When you wrote :

from math import *
# This imports all the functions and the classes from math
# log method is also imported.
# But there is nothing defined with name math

So, When you try using math.log

It gives you error, so :

replace math.log with log

Or

replace from math import * with import math

This should solve the problem.


Change

from math import *

to

import math

Using from X import * is generally not a good idea as it uncontrollably pollutes the global namespace and could present other difficulties.

Tags:

Python