Created
August 9, 2021 18:37
-
-
Save SirMefju/8851f38cbf1cbc47d75158e86f7c30ff to your computer and use it in GitHub Desktop.
Python - Delta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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