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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education