Skip to content

Instantly share code, notes, and snippets.

@SirMefju
Created August 9, 2021 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirMefju/8851f38cbf1cbc47d75158e86f7c30ff to your computer and use it in GitHub Desktop.
Save SirMefju/8851f38cbf1cbc47d75158e86f7c30ff to your computer and use it in GitHub Desktop.
Python - Delta
import os
from time import sleep
print("Delta calculation:")
def calc_delta():
a = float(input("Gimme 'a' "))
b = float(input("Gimme 'b' "))
c = float(input("Gimme 'c' "))
delta = b * b - 4.0 * a * c
print("Delta: " + str(delta))
element_delta = delta ** 0.5
print("Element of delta: " + str(element_delta))
if delta > 0:
xi = ((-b - element_delta) / 2 * a)
xii = ((-b + element_delta) / 2 * a)
print("Solution I = " + str(xi) + "\nSolution II = " + str(xii))
elif delta == 0:
xo = -b / (2 * a)
print("Because Delta = 0, u have only one solution = " + str(xo))
else:
print("You don't have real solutions.")
while True:
calc_delta()
while True:
answer = str(input('Run again? (y/n): '))
if answer in ('y', 'n'):
break
print("Invalid input!")
if answer == 'y':
os.system("cls")
continue
else:
print("Goodbye!")
sleep(2)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment