Program to find roots of a quadratic equation in Python.
In this post, you will learn to find the roots of a quadratic equation with python.
The Logic
- We will ask the user to one by one input all the coefficients of the the quadratic equation.
- Then we are going to use the quadratic formula, i.e. Sridharacharya formula to find the roots of the equation.
- Then we will check if both the roots are equal or not
- If both are unequal, we will print them else, we will print one root.
The Code
a = int(input("Enter the coefficient of x\u00b2: "))
b = int(input("Enter the coefficient of x: "))
c = int(input("Enter the numerical coefficient: "))
eq_p = (-b + (b**2 - 4*a*c)**(1/2)) / 2*a
eq_n = (-b - (b**2 - 4*a*c)**(1/2)) / 2*a
if eq_p != eq_n:
print("The roots of the quadratic equations are:", eq_p, "and", eq_n)
else:
print("The root of the quadratic equations is:", eq_p)
The Output
Make your own Web Browser in Python using PyQt5. PyQt5 is a very powerful Python framework to make modern GUIs. With help of Python PyQt5 QtWebWidgets, it is very easy to amke your own custom web browser with a few lines of code.
PyQt5 Basic code
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class MainWindow(QMainWindow):
def __init__(self):
# Main Window
super(MainWindow, self).__init__()
self.showMaximized()
app = QApplication(sys.argv)
QApplication.setApplicationName("Browser")
window = MainWindow()
app.exec_()
0 Comments