Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a python program to determine the real roots of the quadratic equation ax^

ID: 3749718 • Letter: W

Question

Write a python program to determine the real roots of the quadratic equation ax^2 + bx + c = 0 (where a =/= 0) after requesting the values of a, b, c. Before finding the roots, ensure that a is nonzero. [Note: The equation has 2, 1, or 0 solutions depending on whether the value of b^2 - 4ac is positive, zero, or negative. In the first two cases, the solutions are given by the quadratic formula (-b +- (b^2 - 4ac)^0.5) / 2a.] See Figure below on the outcome of the programming question.

Enter a: 1

Enter b: -11

Enter c: 28

Solutions: 7 and 4

Enter a: 1

Enter b: -11

Enter c: 28

Solutions: 7 and 4

Explanation / Answer

import sys

a=int(input("Enter a: "))

b=int(input("Enter b: "))

c=int(input("Enter c: "))

d=b**2-4*a*c

temp=d**0.5

if(a==0):

print(" Value of a can't be zero")

sys.exit()

if(d<0):

print(" Roots are imaginary. ")

else:

root1=(-b+temp)/2*a

root2=(-b-temp)/2*a

print("The first root is : ",round(root1,2))

print("The second root is : ",round(root2,2))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote