Could you make sure the code is correct. Please read the instructions carefully and the example runs. Thanks.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.4: A Case Study: Rectangular To Polar Coordinate Conversion
Problem 3E
icon
Related questions
Question
Could you make sure the code is correct. Please read the instructions carefully and the example runs. Thanks.
import math
def determinant (a, b, c):
return b**2-4*a*c
def root1(a, b, c):
return (-b+math.sqrt(b**2-4*a*c))/(2*a)
def root2(a, b , c):
return (-b-math.sqrt(b**2-4*a*c))/(2*a)
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
C = float(input ("Enter coefficient c: "))
D = determinant (a, b, c)
if D
0:
==
', root1(a, b, c))
|3D
print("That quadratic has one root:
elif D > 0:
print("That quadratic has two roots: ", root1(a, b, c), "and", root2(a, b, c))
lelse:
print("Sorry, that quadratic has complex roots.")
Transcribed Image Text:import math def determinant (a, b, c): return b**2-4*a*c def root1(a, b, c): return (-b+math.sqrt(b**2-4*a*c))/(2*a) def root2(a, b , c): return (-b-math.sqrt(b**2-4*a*c))/(2*a) a = float(input("Enter coefficient a: ")) b = float(input("Enter coefficient b: ")) C = float(input ("Enter coefficient c: ")) D = determinant (a, b, c) if D 0: == ', root1(a, b, c)) |3D print("That quadratic has one root: elif D > 0: print("That quadratic has two roots: ", root1(a, b, c), "and", root2(a, b, c)) lelse: print("Sorry, that quadratic has complex roots.")
17:51 Sun Feb 27
* 100%
T
Ask the user for the coefficients a, b and c of a quadratic equation ar + br +c = 0.
Implement solving for the roots -
of the quadratic equation. If there is only one root, print it. If the roots are complex, print an error message.
You are required to:
• Write a function to determine and return the determinant b - 4ac from the coefficients. (Hint: This function will make it easy for you to tell how many roots the
equation has.)
• Write a function to determine and return the first root-
• Wite a function to determine and return the second root -
v
from the coefficients.
from the coefficients.
It's up to you how to put together the conditions and output from there.
Example runs:
- RESTART: C:/Users/matth/Desktop/quad.py
Enter coefficient a: 2.0
Enter coefficient b: 4.0
Enter coefficient c: 2.0
That quadratic has one root: -1.0
>>>
- RESTART: C:/Users/matth/Desktop/quad.py
Enter coefficient a: 2.0
Enter coefficient b: 3.0
Enter coefficient c: 2.0
Sorry, that quadratic has complex roots.
>>>
RESTART: C:/Users/matth/Desktop/quad.py
Enter coefficient a: 2.0
Enter coefficient b: 5.0
Enter coefficient c: 2.0
That quodratic has two roots: -0.5 and -2.0
RESTART: C:/Users/matth/Desktop/quad.py
Enter coefficient a: 3.0
Enter coefficient b: 8.0
Enter coefficient c: 2.0
That quadratic has two roots: -0.2792407799438735 and -2.3874258867227933
5
Transcribed Image Text:17:51 Sun Feb 27 * 100% T Ask the user for the coefficients a, b and c of a quadratic equation ar + br +c = 0. Implement solving for the roots - of the quadratic equation. If there is only one root, print it. If the roots are complex, print an error message. You are required to: • Write a function to determine and return the determinant b - 4ac from the coefficients. (Hint: This function will make it easy for you to tell how many roots the equation has.) • Write a function to determine and return the first root- • Wite a function to determine and return the second root - v from the coefficients. from the coefficients. It's up to you how to put together the conditions and output from there. Example runs: - RESTART: C:/Users/matth/Desktop/quad.py Enter coefficient a: 2.0 Enter coefficient b: 4.0 Enter coefficient c: 2.0 That quadratic has one root: -1.0 >>> - RESTART: C:/Users/matth/Desktop/quad.py Enter coefficient a: 2.0 Enter coefficient b: 3.0 Enter coefficient c: 2.0 Sorry, that quadratic has complex roots. >>> RESTART: C:/Users/matth/Desktop/quad.py Enter coefficient a: 2.0 Enter coefficient b: 5.0 Enter coefficient c: 2.0 That quodratic has two roots: -0.5 and -2.0 RESTART: C:/Users/matth/Desktop/quad.py Enter coefficient a: 3.0 Enter coefficient b: 8.0 Enter coefficient c: 2.0 That quadratic has two roots: -0.2792407799438735 and -2.3874258867227933 5
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning