-2

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.

MattDMo
  • 100,794
  • 21
  • 241
  • 231

2 Answers2

1

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

The Thonnu
  • 3,578
  • 2
  • 8
  • 30
1

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

import math