
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Solve Quadratic Equation using Python
You can use the cmath module in order to solve Quadratic Equation using Python. This is because roots of quadratic equations might be complex in nature. If you have a quadratic equation of the form ax^2 + bx + c = 0, then,
Example
import cmath
a = 12 b = 8 c = 1 # Discriminent d = (b**2) - (4*a*c) root1 = (-b - cmath.sqrt(d)) / (2 * a) root2 = (-b + cmath.sqrt(d)) / (2 * a) print(root1) print(root2)
Output
This will give the output
(-0.5+0j) (-0.16666666666666666+0j)
Advertisements