Itssuman1808

FIND NO OF ROOT OF A quadratic equation ax^2+bx+c=0

Apr 28th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # A quadratic equation ax^2+bx+c=0 has either 0, 1, 2 distinct solutions for real values of x
  2. #Given a, b, c you should return the number of solutions to the equation.
  3. # Python program to find roots
  4. # of a quadratic equation
  5. import math
  6. # Prints roots of quadratic equation
  7. # ax*2 + bx + x
  8. def findRoots( a, b, c):
  9.  
  10.   # a is always positive
  11.   if a <= 0:
  12.     print("Invalid")
  13.     return -1
  14.   d = b * b - 4 * a * c
  15.   sqrt_val = math.sqrt(abs(d))
  16.  
  17.   if d > 0:
  18.     print("2")
  19.   elif d == 0:
  20.     print("1")
  21.   else: #d<0
  22.     print("2")
  23.        
  24. a = -1
  25. b = 0
  26. c = 0
  27. findRoots(a, b, c)
Add Comment
Please, Sign In to add comment