Answer to Question #303735 in Python for petals

Question #303735

Write a program to solve a quadratic equation ax2 + bx + c = 0. Always check if the discriminant (D)

> 0, then the equations has two roots

= 0, then the equation has one root (two equal roots)

< 0, the equation has no real roots 

where    D = square root of b2 - 4ac


1
Expert's answer
2022-02-28T01:08:37-0500
a = int(input())
b = int(input())
c = int(input())
# a^2 + bx + c = 0
d = b ** 2 - 4 * a * c
if d > 0:
  print('x1 =', (-b-sqrt(d)) / (2*a))
  print('x2 =', (-b+sqrt(d)) / (2*a))
elif d == 0:
  print('x1 = x2 =', -b / (2*a))
else:
  print('No roots')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS