import math  #importing math-module
      # take inputs
      a = int(input('Enter the value of a: '))
      b = int(input('Enter the value of b: '))
      c = int(input('Enter the value of c: '))
      # calculate discriminant
      dis = (b**2) - (4*a*c)
      # checking condition for discriminant
      if(dis > 0):
          root1 = (-b + math.sqrt(dis) / (2 * a))
          root2 = (-b - math.sqrt(dis) / (2 * a))
          print("Two distinct real roots are %.2f and %.2f" %(root1, root2))
      elif(dis == 0):
          root1 = root2 = -b / (2 * a)
          print("Two equal and real roots are %.2f and %.2f" %(root1, root2))
      elif(dis < 0):
          root1 = root2 = -b / (2 * a)
          imaginary = math.sqrt(-dis) / (2 * a)
          print("Two distinct complex roots are %.2f+%.2f and %.2f-%.2f" 
                                %(root1, imaginary, root2, imaginary))
      
      Python language logo

      Quadratic Equation

      maths
      logic
      solvingEquations

      Solving a given quadratic equation. The nature of the roots are given as, If discriminant>1 then the roots are real and different If discriminant=0 then the roots are real and equal If discriminant<1 then the roots are complex and different For the quadratic equation ax² + bx + c = 0, if we denote the discriminant as d, then their roots

      If d>1 then the roots are real and different root1 = (-b + √d)/2a root2 = (-b – √d)/2a If d=0 then both roots are -b/2a

      If d<1 then roots are complex and different root1 = -b/2a + i (√d/2a) root2 = -b/2a – i (√d/2a)

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.