Write a function numsols2deg(a, b, c) that receives as argument the three coefficients of the 2nd degree equation ax2 + bx + c = 0 and returns how many real solutions it has: 0, 1, or 2.
The solutions of that equation are given by the expression x = (−b ± √b2 − 4ac)/2a (best seen in the pdf version of the statement).
The expression b2 − 4ac is called its discriminant: if it is negative, then the square root cannot provide real values, and there are no real solutions; if the discriminant is 0, then the square root is also 0 and the two options −b ± 0 coincide, so that there is a single real solution; if the discriminant is positive, then we obtain two real solutions.
>>> numsols2deg(3, 5, 2) 2 >>> numsols2deg(1, 2, 1) 1 >>> numsols2deg(1, 1, 1) 0 >>> numsols2deg(-2, 2, 2) 2