Number of Real Solutions for Degree 2 X60334


Statement
 

pdf   zip

Write a function @numsols2deg(a, b, c)@ that receives as argument the three coefficients of the 2nd degree equation ax2+bx+c=0ax^2 + 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±b24ac)/2ax = (-b \pm \sqrt{b^2 - 4ac})/2a (best seen in the pdf version of the statement).

The expression b24acb^2 - 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-b \pm 0 coincide, so that there is a single real solution; if the discriminant is positive, then we obtain two real solutions.

Sample session

Sample session
>>> numsols2deg(3, 5, 2)
2
>>> numsols2deg(1, 2, 1)
1
>>> numsols2deg(1, 1, 1)
0
>>> numsols2deg(-2, 2, 2)
2
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python