Skip to content

Instantly share code, notes, and snippets.

@DhruvDazer
Created September 5, 2020 14:41
# Taking input from user for the equation ax2 +bx + c
a= float(input("Please enter the coefficient of the x2 term: "))
b= float(input("Please enter the coefficient of the x term: "))
c= float(input("Please enter the constant term: "))
# Calculation of the roots of quadratic equation using the quadratic formula
import math
d= b**2 - 4*a*c
if d<0:
print("As the discriminant in the equation is equal to zero, it doesn't have real roots.")
else:
root1= ((-b) + math.sqrt(d))/(2*a)
root2= ((-b) - math.sqrt(d))/(2*a)
print("The roots of this quadratic equation are: ", root1, " and " , root2, " .")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment