-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquadratic.py
More file actions
33 lines (21 loc) · 807 Bytes
/
quadratic.py
File metadata and controls
33 lines (21 loc) · 807 Bytes
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
# A program that computes the real roots of a quadratic equation.
#Illustrates use of math library
#NOTE: The program crashes if there is no real root for the equation
import math #It makes the math library available
def main():
print('This program finds real roots to a quadratic equation')
print()#to create empty line
# float allows the use of decimal
a=float(input('Enter coefficient a: '))
b=float(input('Enter coefficient b: '))
c=float(input('Enter coefficient c: '))
disc = b**2 - 4*a*c
if disc <0:
print('Sorry, your equation has no real root')
else:
discroot = math.sqrt(disc)
root1=(-b+discroot)/(2*a)
root2=(-b-discroot)/(2*a)
print()
print('The roots are ' ,root1,root2)
main()