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

(hint: use the function real and imag! also i is imaginary #) You are to write a

ID: 3586080 • Letter: #

Question

(hint: use the function real and imag! also i is imaginary #)

You are to write a script called ekl25homeworklb that will prompt the user for three numbers which are the coefficients of your polynomial, specifically: a,b, and c seen previously. Then you are to find the root(s), either real or imaginary and print them in the specific format seen below. There is an example for each different case >ek125homeworklb Enter the coefficient of x2: 1 Enter the coefficient of x: -3 Enter the constant: 2 The polynomial (x2+ (-3) x+ (2) has roots 2.00 and 1.00 >ek125homeworklb Enter the coefficient of x2: 1 Enter the coefficient of x: -6 Enter the constant: 9 The polynomial (x2+ (-6) x+ (9) has root 3.00 >ek125homeworklb Enter the coefficient of x2: 4 Enter the coefficient of x: 2 Enter the constant: 4 The polynomial (A)x 2+ (2) x+ (4) has roots -0·25+(0.97) and 0.25+(-0.97)

Explanation / Answer

import math

a = int(input("Enter the coefficient of x^2 :"))
b = int(input("Enter the coefficient of x :"))
c = int(input("Enter the constant :"))

if b*b-4*a*c > 0:
   x1 = -b/(2*a) + math.sqrt(b*b-4*a*c )/(2*a)
   x2 = -b/(2*a) - math.sqrt(b*b-4*a*c )/(2*a)
   print("has roots",end = " ")
   print ("%.2f" %x1,end = " ")
   print ("%.2f" %x2)
if b*b-4*a*c < 0:
   x1 = -b/(2*a)
   im = math.sqrt(-(b*b-4*a*c))/(2*a)
   print("has roots",end = " ")
   print ("%.2f" %x1,"+",end = "")
   print ("(+%.2f)" %im+"i",end = "")
   print(" and ",end = "")
   print ("%.2f" %x1,"+",end = "")
   print ("(-%.2f)" %im +"i",end = "")
   print()
if b*b-4*a*c == 0:
   x1 = -b/(2*a)
   print("has root",end = " ")
   print ("%.2f" %x1)