31.5k views
5 votes
Input Format:

Get a, b, and c as input.

Output Format:

Output “Yes” or “No” depending on if the given quadratic is factorable. If it is

factorable, output the roots in increasing order. If there are two of the exact same roots, only output it once. Round roots to the nearest hundredth.

Sample Input Sample Output

1 1 -1 Yes -1.00, 0.00

1 3 2 Yes -2.00, -1.00

2 1 2 No

1 Answer

5 votes

In python 3:

import math

def quadratic(a, b, c):

if (b ** 2) - (4 * a * c) < 0:

return "No"

root1 = round((-b + (math.sqrt((b ** 2) - (4 * a * c)))) / (2 * a), 2)

root2 = round((-b - (math.sqrt((b ** 2) - (4 * a * c)))) / (2 * a), 2)

lst = ([])

lst.append(root1)

lst.append(root2)

lst.sort()

return f"Yes {lst[0]}, {lst[1]}"

print(quadratic(1, 3, 2))

The print statement tests the function. I hope this helps!

User NcJie
by
8.2k points

Related questions

asked Jul 25, 2024 232k views
Boey asked Jul 25, 2024
by Boey
8.4k points
1 answer
3 votes
232k views
asked Mar 14, 2024 63.3k views
Mike Yan asked Mar 14, 2024
by Mike Yan
7.0k points
1 answer
0 votes
63.3k views
asked Oct 23, 2024 220k views
Szkra asked Oct 23, 2024
by Szkra
8.3k points
1 answer
3 votes
220k views