alberbeto2
alberbeto2

Reputation: 1

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

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.

Upvotes: -2

Views: 122

Answers (2)

Piotr Grzybowski
Piotr Grzybowski

Reputation: 594

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

import math

Upvotes: 1

The Thonnu
The Thonnu

Reputation: 3624

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

Upvotes: 1

Related Questions