Learn
Did you see that? Python said: NameError: name 'sqrt' is not defined.
Python doesn’t know what square roots are—yet.
There is a Python module named math
that includes a number of useful variables and functions, and sqrt()
is one of those functions. In order to access math
, all you need is the import
keyword. When you simply import a module this way, it’s called a generic import.
Instructions
1.
You’ll need to do two things here:
- Type
import math
on line 2 in the editor. - Insert
math.
beforesqrt()
so that it has the formmath.sqrt()
. This tells Python not only toimport math
, but to get thesqrt()
function from withinmath
. Then hit Run to see what Python now knows.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.