-
Notifications
You must be signed in to change notification settings - Fork 0
/
quadratic.py
40 lines (40 loc) · 1.24 KB
/
quadratic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def solve(a, b, c):
if a==0:
x = -c/b
print("The single value for x is:", x)
elif b==0:
if c>0:
x = (c/a)**(0.5)
print("The values of x are: ±", x, "*i")
else:
x = (-c/a)**(0.5)
print("The values of x are: ±", x)
elif c==0:
x = -b/a
print("The values for x are:", x, "and 0")
else:
dis = b**2-4*a*c
if dis>0:
x1 = (-b+dis**(0.5))/(2*a)
x2 = (-b-dis**(0.5))/(2*a)
print("The values of x are:", x1, "and ", x2)
elif dis==0:
x = -b/(2*a)
print("The single value for x is:", x)
elif dis<0:
idis = (dis*-1)**(0.5)/(2*a)
x = (-b)/(2*a)
print("The values of x are:", x, "±", idis, "*i")
else:
print("Follow the instructions, please.")
print("To exit the program, input 0 three times")
print("Please structure your input accordingly:")
print("(a)x^2 + (b)x + (c) = 0")
while True:
a= float(input("a = "))
b= float(input("b = "))
c= float(input("c = "))
if a == 0 and b == 0 and c == 0:
print("Exiting the program.")
break
solve(a,b,c)