Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A quadratic equation ax^2+bx+c=0 has either 0, 1, 2 distinct solutions for real values of x
- #Given a, b, c you should return the number of solutions to the equation.
- # Python program to find roots
- # of a quadratic equation
- import math
- # Prints roots of quadratic equation
- # ax*2 + bx + x
- def findRoots( a, b, c):
- # a is always positive
- if a <= 0:
- print("Invalid")
- return -1
- d = b * b - 4 * a * c
- sqrt_val = math.sqrt(abs(d))
- if d > 0:
- print("2")
- elif d == 0:
- print("1")
- else: #d<0
- print("2")
- a = -1
- b = 0
- c = 0
- findRoots(a, b, c)
Add Comment
Please, Sign In to add comment