Solving a quadratic equation¶
If we have an equation in the form ax2 + bx + c = 0, to solve x the following formula is applied:
In Python, recall that multiplication is done with an asterisk * while power is indicated by two **. For example, 2*3 is 6 y 2**3 is 8.
The square root can be calculated using 1/2 as the right operand of the power operator, for instance 4**(1/2) will equal 2.
To ask a user to enter data, the input() function is used. This function admits as a parameter a text that will be shown to the user as an aid to request the input data. For example, text = input("Enter a text: ")
If we want the entered text to be treated as an integer in order to perform mathematical operations, we must convert it using the int() function. This is also called casting. For example, number = int(input("Enter an integer number: ")
If we want the entered number to have decimals, the conversion must be done using the float() function. For example, floating_number = float(input("Enter a float number: ")
So far, with all the previous explanation, develop the following program:
A program to calculate the solution to a quadratic equation like ax2 + bx + c = 0. It will ask the user for the values of a, b and c, calculate x (possibly have 2 solutions) and print the result on the screen.