Python Program to find roots of a Quadratic Equation

Updated: May 18


Program:


a = int(input("Enter the value of a : ")) b = int(input("Enter the value of b : ")) c = int(input("Enter the value of c : ")) dis = (b * b) - (4 * a * c) if(dis > 0): r1=(-b + math.sqrt(dis)) / (2 * a) r2=(-b - math.sqrt(dis)) / (2 * a) print("Two Distinct Real Roots Exists: r1 = %.2f and r2 = %.2f" %(r1, r2)) elif(dis == 0): r1 = r2 = -b / (2 * a) print("Two Equal and Real Roots Exists: r1 = %.2f and r2 = %.2f" %(r1, rt2)) elif(dis < 0): r1 = r2 = -b / (2 * a) imaginary=math.sqrt(-dis) / (2 * a) print("Two Distinct Complex Roots Exists: r1 = %.2f+%.2f and r2 = %.2f-%.2f" %(r1, imaginary, r2, imaginary))




Recent Posts

See All

Python Program to add Two numbers

Program: num1 = int (input(" Please Enter the First Number: ")) num2 = int (input(" Please Enter the second number: ")) sum = num1+num2 print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) O