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 raices de una ec cuadratica
- """
- from datetime import datetime
- from math import sqrt
- def ingresar_datos():
- a = float(input("Ingrese el termino cuadratico a: "))
- b = float(input("Ingrese el termino lineal b: "))
- c = float(input("Ingrese el termino independiente c: "))
- return [a,b,c]
- def calcular_raices(a,b,c):
- delta = b**2 - 4*a*c
- if delta == 0:
- raiz = -1*b / (2*a)
- return raiz
- elif delta > 0:
- raiz1 = (-1*b + sqrt(delta)) / (2*a)
- raiz2 = (-1*b - sqrt(delta)) / (2*a)
- return [raiz1, raiz2]
- else:
- return "No hay raices"
- def imprimir_raices(raices):
- if isinstance(raices, float):
- print("Existe una solución: {:.2f}".format(raices))
- elif isinstance(raices, list):
- print("Existen dos soluciones: {:.2f} y {:.2f}".format(raices[0], raices[1]))
- else:
- print(raices)
- def grabar_datos(a,b,c,raices):
- # abro el archivo
- f = open("resultados.txt","a")
- f.write(datetime.now().strftime("%d/%m/%y %H:%M:%S") + "\n")
- f.write("Parametros:\n")
- f.write(f"a: {a}\n")
- f.write(f"b: {b}\n")
- f.write(f"c: {c}\n")
- while True:
- print("\nScript para calcular raices de una ec. cuadrática")
- a,b,c = ingresar_datos()
- raices = calcular_raices(a,b,c)
- imprimir_raices(raices)
- grabar_datos(a,b,c,raices)
- opcion = input("Presione cualquier tecla o '1' para salir: ")
- if opcion == "1":
- print("Gracias por usar este programa...")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement