Question

Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, 0, can be obtained using the following fomula: b 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no real roots. Write a program that prompts the user to enter values for a, b, and cand displays the result based on the discriminant. If the discriminant is positive. display two roots. If the discriminant is o, display one root. Otherwise, display The equation has no real roots. Here are some sample runs. Enter a, b, c: 1.0. 3, 1 The roots are -0.381966 and -2.61803 Enter a, b, c: 1, 2.0, The root 1s -1 Enter a, b, c: 1. 2. 3 The equation has no real roots
This is in python language
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#code.py
print("Enter a, b, c: ")
[a, b, c] = [float(x) for x in input().split(", ")]
d = b * b - 4.0 * a * c
if (d < 0):
    print("The equation has no real roots")
elif (d == 0):
    root1 = -b / (2.0 * a)
    print("The root is %f"%root1)
elif (d > 0 ):
    root1 =(-b + d**0.5) / (2.0 * a)
    root2 =(-b - d**0.5) / (2.0 * a)
    print("The roots are %f and %f" % (root1, root2))

Output:

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
This is in python language Algebra: solve quadratic equations) The two roots of a quadratic equation,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, , can be...

    (Algebra: solve quadratic equations) The two roots of a quadratic equation, for example, , can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac) / (2a) and r1 = (-b - sqrt(b^2 - 4ac) / (2a) b^2 - 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no real roots....

  • In Python. The two roots of a quadratic equation ax^2 + bx + c = 0...

    In Python. The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac) / (2a) and r2 = (-b - sqrt(b^2 - 4ac) / (2a) b^2 - 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no...

  • Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c...

    Use Python Programming. Design a class named Quadratic Equation for a quadratic equation ax + bx+c 0. The class contains: • The data fields a, b, and c that represent three coefficients. . An initializer for the arguments for a, b, and c. • Three getter methods for a, b, and c. • A method named get Discriminant() that returns the discriminant, which is b- 4ac The methods named getRoot 1() and getRoot 2() for returning the two roots of...

  • Rule book: 1.)Must be Python - 2.) no imported module (ie cmath) - no can do...

    Rule book: 1.)Must be Python - 2.) no imported module (ie cmath) - no can do on the imports... pure code.. 3.) numbers are float - not integer. Here's the prompt: (Algebra: solve quadratic equations) The two roots of a quadratic equation ax^2 + bx + c = 0 can be obtained using the following formula: r1 = (-b + sqrt(b^2 - 4ac)) / (2a) and r2 = (-b - sqrt(b^2 - 4ac)) / (2a) b^2 - 4ac is called...

  • C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠...

    C++ The roots of the quadratic equation ax² + bx + c = 0, a ≠ 0 are given by the following formula: In this formula, the term b² - 4ac is called the discriminant. If b² - 4ac = 0, then the equation has a single (repeated) root. If b² - 4ac > 0, the equation has two real roots. If b² - 4ac < 0, the equation has two complex roots. Instructions Write a program that prompts the...

  • The roots of the quadratic equation ax2 + bx + c = 0, a following formula:...

    The roots of the quadratic equation ax2 + bx + c = 0, a following formula: 0 are given by the In this formula, the term i2 - 4ac is called the discriminant. If b4ac 0 then the equation has a single (repeated) root. If -4ac > 0, th equation complex roots. Write a program that prompts the user to input the value of a (the coefficient of ), b (the coefficient of x), and c (the n has two...

  • Write a C program, to solve the quadratic equation a x2 + b x + c...

    Write a C program, to solve the quadratic equation a x2 + b x + c = 0 of given coefficients a, b and c. When running the program, it prompts for the input of coefficients a,b,c as floating numbers. After inputting three floating numbers, it computes and prints out the solutions, then prompts for another round of input. Your program will quit when getting input 0,0,0. Your program should handle four situations: (1) a=0, not a quadratic equation; (2)...

  • reword m the program into a design document diregard the m Write a C++ program that...

    reword m the program into a design document diregard the m Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula -b + b2 - 4ac 2a The value of the discriminant b2 - 4ac determines the nature of roots. If the value of the discriminant is zero, then the equation has a single...

  • 4-6 on matlab 4. Write a program in a script file that determines the real roots...

    4-6 on matlab 4. Write a program in a script file that determines the real roots of a quadratic equation ax2+bx+c 0 When the file runs, it asks the user to enter the values of the constants a, b, and c. To calculate the roots of the equation the program calculates the discriminant D, given by: D b2-4ac When D 0, the program displays message "The equation has two roots," and the roots are displayed in the next line. When...

  • The two roots of the quadratic equation ax2 + bx + c = 0 can be...

    The two roots of the quadratic equation ax2 + bx + c = 0 can be found using the quadratic formula as -b+ v62 – 4ac . -b-v6² – 4ac 1 X1 = - and x2 = 2a 2a When b2 – 4ac < 0 this yields two complex roots - -b V4ac – 62 -b Vac – 6² x1 = = +. . 2a 2a i. and x2 = . za 2al Using the quadratic formula the roots of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT