solve a second degree equation in python

Solutions on MaxInterview for solve a second degree equation in python by the best coders in the world

showing results for - "solve a second degree equation in python"
Hajar
03 Sep 2016
1import math
2print ("The second degree equation comes in the form")
3print("ax²+bx+c")
4a =int (input("Enter a: "))
5b =int (input("Enter b: "))
6c =int (input("Enter c: "))
7
8d = (b**2)-(4*a*c) 
9
10if d < 0:
11    print ("This equation has no real solution")
12elif d == 0:
13    x = (-b+math.sqrt(d))/2*a
14    print ("This equation has one solutions: ", x)
15else:
16    x1 = (-b+math.sqrt(d))/2*a
17    x2 = (-b-math.sqrt(d))/2*a
18    print ("This equation has two solutions: ", x1, " and", x2)