Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equation ar+ br + c= 0. The program should display the solut ions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with 4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solut ions, each displayed with 4 digits printed out after the decimal place. 3. If the equation has solutions that are not real numbers, display COMPLEX SOLUTIONS:, followed by two solutions displayed in the form a + bi, where each a and b should be displayed with 4 digits printed out after the decimal place.
![1) quadratic.Py
Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equation ar+ br + c = 0.
The program should display the solut ions of this equation, in the following manner:
1. If the equation has one solution, display ONE SOLUTION:, followed by the solut ion, displayed with 4 digits printed out
after the decimal place.
2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with
4 digits printed out after the decimal place.
3. If the equation has solutions that are not real numbers, display COMPLEX SOLUTIONS:, followed by two solutions
displayed in the form a + bi, where each a and b should be displayed with 4 digits printed out after the decimal place.
For example, a run might look like
Enter x 2 coefficient: 1
Ent er x1 coefficient: -2
Enter x0 coefficient: 1
ONE SOLUTION: x = 1.0000
or
Ent er x*2 coefficient: 3
Enter x1 coefficient: 5
Enter x"0 coefficient: 1
TWO REAL SOLUTIONS: I = -0.2324 and x = -1.4343
or
Ent er x 2 coefficient: 2.1
Ent er 1*1 coefficient : 4
Enter x"0 coefficient: 10
COMPLEX SOLUTIONS: x = -0.9524 - 1.9634i and I = -0.9524 + 1.9634i
In the last case, note that the letter that is printed out to represent the square root of -1 is the letter i, not the letter j!
Python has some funct ions that produce complex values, but when you print these values, they will display the letter j to
represent v-1. I don't want that
code which prints out the string "i". Do not use the cmath module, the complex function, the .imag attribute,or
any Python functions that perform replacements in strings. (If you don't know whyat any of those are. don't worry
about, it.)
so, instead, your program should calculate the imaginary coefficient, and then include
Specifications: your program must
• ask for and accept coefficients from the user.
• assuming that the user enters a non-zero leading coefficient. display the type of solut ions as above. (In the case w here
there is exactly one solution, it is acceptable if the program occasionally misidentifies it. although it should work with
the example I've provided.)
• display all solutions with exactly 4 digits printed aft er each decimal (for complex solutions. 4 digits after the decimal for
both real and imaginary parts).
• use the letter i to represent V-1 in output. not the letter j.
• not use the cmath module, the complex funct ion, the.imag attribute. or any Python functions that perform
replacements in strings.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc53cf867-9bc1-4521-baf8-6da1a12ea6d9%2F03477a8e-d406-4595-acc1-e384d04220c1%2F5o6dsqs_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Sample Response:
#Python program to find the roots of quadratic equation
import math
# function to finding roots
def equationroots(a,b,c):
#compute discriminant
dis=b*b-4*a*c
sqrt_val=math.sqrt(abs(dis))
#check the Discriminant and generates the solution
if dis>0:
print("TWO REAL SOLUTIONS: x = {0:.4f}".format((-b+sqrt_val)/(2*a))," and x = {0:.4f}".format((-b -sqrt_val)/(2*a)))
elif dis==0:
print("ONE SOLUTION: x = {0:.4f}".format(-b/(2*a)))
else:
print("COMPLEX ROOTS: x = {0:.4f}".format((-b/(2*a))),"+ {0:.4f}".format(sqrt_val),"i and x = {0:.4f}".format((-b/(2*a))),"- {0:.4f}".format(sqrt_val),"i")
#Driver Program
a=float(input("Enter x^2 coefficient: "))
b=float(input("Enter x^1 coefficient: "))
c=float(input("Enter x^0 coefficient: "))
# If a is 0, then incorrect equation
if a==0:
print("Input correct quadratic equation")
else:
equationroots(a, b, c)
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)