Aaron Plana
Aaron Plana

Reputation: 23

Python in Visual Studio - Math doesn't work

I have some problems with the function Math and sqrt in Visual studio, does anyone can say me what i'm doing wrong?

print("Programa de calculo de raiz cuadrada")

numero= int(input("Introduce un numero: "))

intentos=0 

while numero<0:

    print("no se puede calcular la raiz de un numero negativo")

    if intentos==2:
        print("Has consumido demasiados intentos, reinicia aplicacion")
        break

    numero= int(input("Introduce un numero: "))
    if numero<0:
        intentos=intentos+1

if intentos<3:
    solución= math.sqrt(numero) # Here's the problem

    print("La raíz cuadrada de" +str(numero) + "es" +str(solución))

Python #VisualStudio

Upvotes: 1

Views: 1914

Answers (1)

John
John

Reputation: 770

You need import math to be able to use the math function.

It also has an error in the variable named solución, must be solucion.

Try this:

import math

print("Programa de calculo de raiz cuadrada")

numero= int(input("Introduce un numero: "))

intentos=0 

while numero<0:

    print("no se puede calcular la raiz de un numero negativo")

    if intentos==2:
        print("Has consumido demasiados intentos, reinicia aplicacion")
        break

    numero= int(input("Introduce un numero: "))
    if numero<0:
        intentos=intentos+1

if intentos<3:
    solucion= math.sqrt(numero)
    print("La raíz cuadrada de " +str(numero) + "es" +str(solucion))

Upvotes: 1

Related Questions