Why math.sqrt in python doesn't work in my sublimeREPL?

112 Views Asked by At

I have written this code in sublime text

if intentos<3:
    solution= math.sqrt(number)
    print("La raiz cuadrada de " + str(number) + "es" + str(solution))

Then I have used sublimeREPL and I don't know why but It has appear this:

Traceback (most recent call last):
  File "prueba.py", line 23, in <module>
    solution= math.sqrt(number)
NameError: name 'math' is not defined

This error only appears when I use math.sqrt and I don not understand why. Moreover, I have copied this exact code from a video tutorial and he does the same as me but for some reason his sublimeREPL works correctly.

2

There are 2 best solutions below

0
The Thonnu On

It gives the error name 'math' is not defined because you haven't defined math.

You need to import it using:

import math

at the start of the program.

Read more in the documentation

0
Piotr Grzybowski On

You miss an import of the math module, please try to add the line at the beginning of your script

import math