Python Solve Quadratic Equation
In this snippet, we will learn how to calculate the area of a triangle in Python.
Formula
Let's see the formula:
ax2 + bx + c = 0
Here a, b and c are real numbers and a ≠ 0.
Example
Now let's see an example:
import cmath
a = 1
b = 4
c = 9
d = (b**2) - (4*a*c)
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
print('The solution are: {0} and {1}'.format(sol1,sol2))
The output:
The solution are: (-2-2.23606797749979j) and (-2+2.23606797749979j)
You can also run the program in our IDE.
Md Obydullah
Software Engineer | Ethical Hacker & Cybersecurity...
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.