Question

3. Produce the function quadratic(a,b,c) where a, b, and c are the coeffi- cients of the quadratic ax2 + bx +c. The function

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import math


def quadratic(a, b, c):
    d = (b * b) - (4 * a * c)
    if d < 0 or a == 0:
        return None

    roots = []
    if d == 0:
        roots.append((-b) / (2 * a))
    else:
        r2 = (-b - math.sqrt(d)) / (2 * a)
        r1 = (-b + math.sqrt(d)) / (2 * a)
        roots.append(r1)
        roots.append(r2)
    return roots


# Testing the function here. ignore/remove the code below if not required print (quadratic(1, 2, 3)) print (quadratic(1, -2,

None [1.0] [1.4142135623730951, -1.4142135623730951] Process finished with exit code o

Add a comment
Know the answer?
Add Answer to:
3. Produce the function quadratic(a,b,c) where a, b, and c are the coeffi- cients of the...
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
  • 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...

  • C program that uses pointers as function arguments to do the following: To exemplify pointers, we...

    C program that uses pointers as function arguments to do the following: To exemplify pointers, we will be doing quadratics. Remember that a quadratic expression is of the form: ax2 + bx + c where a. b, c are constant and a is not 0. You will scan in the values a. b. and c. With these values, you will write three functions: quadraticFormula quadraticVertex quadratic Info The first function will perform the quadratic equation to find the roots of...

  • Using matlab and if/else statement please! Write a function that determines the real roots of a...

    Using matlab and if/else statement please! Write a function that determines the real roots of a quadratic equation ax2 + bx + c = 0. To calculate the roots of the equation, the function calculates the discriminant D, given by: D = b2-4ac If D> 0, the code should display "The equation has two roots" and print the values on a new line. If D 0, the code should display "The equation has one root.", and print the value on...

  • 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...

  • write a function of quadratic choice. it must take in at least one parameter, and perform...

    write a function of quadratic choice. it must take in at least one parameter, and perform some task. the reslut will be returned to main, and printed. here is the sample but this sample still not complete because this sample still need to return root1 and root2 to the main. sample: def juneQuadratic(a,b,c):    root1 = (-b + math.sqrt(b**2 - (4*a*c)) )/2*a root2 = (-b - math.sqrt(b**2 - (4*a*c)) )/2*a return (root1,root2) def main(): rootsTupleFromFunction = juneQuadratic(2,8,5) print(rootsTupleFunction) print("Root 1...

  • A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the...

    A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...

  • write a C programming code for the following prompt. please use stucture concept and test if...

    write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...

  • 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...

  • CODE MUST BE IN C++ Objective Create a program that provides the solution to a quadratic...

    CODE MUST BE IN C++ Objective Create a program that provides the solution to a quadratic equation. Background: A quadratic equation can be generalized by equation below: f ( x )=ax2+ bx +c Closed form solutions can be found for the zeros of a quadratic function conveniently. That is the locations where the function is equal to zero can be found by the following equation: x=− b± √ b −4ac 2a Note that depending on the sign of the expression...

  • Complete 1. Create a function to solve the Quadratic Formula as know as ax +bx+cwit solution...

    Complete 1. Create a function to solve the Quadratic Formula as know as ax +bx+cwit solution is 2a The function must have only 3 reference parameters which are the coefficient of the quadratic equation a, b and c, at the end the function must return the real value of x. If a-0, or there is a negative root square obtained, the function must sent a message error to the user The coefficient of it can't be equal zero" or "Negative...

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
ADVERTISEMENT