Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- Script que calcula las posibles soluciones de una raíz cuadrada de un
- número real. Si no existe, imprime una cartel indicando tal situación
- """
- def calcular_raiz(numero):
- from math import sqrt
- if numero < 0:
- return "NO EXISTE la raiz cuadrada de un nro. negativo en el campo de los reales"
- elif numero == 0:
- return 0
- else:
- return [sqrt(numero),-1*sqrt(numero)]
- def imprimir_raices(raices):
- if isinstance(raices,str):
- print(raices)
- elif isinstance(raices, int):
- print(f"Existe una única raiz: {raices}")
- else:
- print(f"Existen dos soluciones: {raices[0]} y {raices[1]}")
- while True:
- numero = float(input("Ingrese un nro: "))
- raices = calcular_raiz(numero)
- imprimir_raices(raices)
- opcion = input("Presione cualquier tecla para continuar ('X' para salir): ")
- if opcion.casefold() == "x":
- print("Gracias por usar este programa...")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement