Dada una ecuación cuadrática, la tarea es resolver la ecuación o encontrar las raíces de la ecuación. La forma estándar de la ecuación cuadrática es:
ax2 + bx + c where, a, b, and c are coefficient and real numbers and also a ≠ 0. If a is equal to 0 that equation is not valid quadratic equation.
# Python program to find roots of quadratic equation import math # function for finding roots def equationroots( a, b, c): # calculating discriminant using formula dis = b * b - 4 * a * c sqrt_val = math.sqrt(abs(dis)) # checking condition for discriminant if dis > 0: print(" real and different roots ") print((-b + sqrt_val)/(2 * a)) print((-b - sqrt_val)/(2 * a)) elif dis == 0: print(" real and same roots") print(-b / (2 * a)) # when discriminant is less than 0 else: print("Complex Roots") print(- b / (2 * a), " + i", sqrt_val) print(- b / (2 * a), " - i", sqrt_val) # Driver Program a = 1 b = 10 c = -24 # If a is 0, then incorrect equation if a == 0: print("Input correct quadratic equation") else: equationroots(a, b, c)
Publicación traducida automáticamente
Artículo escrito por simran_bhandari y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA