-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuadratics.py
34 lines (31 loc) · 897 Bytes
/
Quadratics.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
import math
# Get data
A = float(input("A:"))
B = float(input("B:"))
C = float(input("C:"))
# Calculate Root from data
if A == 0:
error = "Math error"
else:
# Calc Discrimant
D = B*B - 4*A*C
if D > 0:
D2 = math.sqrt(D)
Root1 =(-B + D2)/(2*A)
Root2 =(-B - D2)/(2*A)
elif D == 0:
DoubleRoot = -B / (2 * A)
else:
D2 = math.sqrt(-D)
RealPart = -B / (2 * A)
ImaginaryPart = D2 / (2 * A)
# Print calculated root
if A == 0:
print(error)
else:
if D > 0:
print("Root1: " +'{:.3f}'.format(Root1).rstrip("0")+"\n Root2: " +'{:.3f}'.format(Root2).rstrip("0"))
elif D == 0:
print("The DoubleRoot is: " +'{:.3f}'.format(DoubleRoot).rstrip("0"))
else:
print("Real part: " +'{:.3f}'.format(RealPart).rstrip("0")+"\n Imaginary part: " +'{:.3f}'.format(ImaginaryPart).rstrip("0"))