Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("programme to solves Quadratic equation (equation of the second degree) ")
- print("this programme solves equations \n like Ax²+Bx+C=0")
- while True:
- num1 = input("Please enter the value of A : ")
- try:
- a = int(num1)
- break
- except ValueError:
- try:
- a = float(num1)
- break
- except ValueError:
- print("This is not a number. Please enter a valid number")
- while True:
- num2 = input("Please enter the value of B : ")
- try:
- b = int(num2)
- break
- except ValueError:
- try:
- b = float(num2)
- break
- except ValueError:
- print("This is not a number. Please enter a valid number")
- while True:
- num3 = input("Please enter the value of C : ")
- try:
- c = int(num3)
- break
- except ValueError:
- try:
- c = float(num3)
- break
- except ValueError:
- print("This is not a number. Please enter a valid number")
- if a == 0 and b == 0:
- print("the resulte is", c, "=0\n it's incorrect equation")
- elif a == 0 and b != 0:
- x = c / b
- print("the val of X is:\n x = ", x)
- elif a != 0 and b == 0:
- from math import sqrt
- from math import fabs
- x = fabs(c / a)
- x = sqrt(x)
- print("the val of X is:\n x1 = ", x, " x2 = -", x)
- else:
- from math import sqrt
- delta = (b ** 2) - (4 * a * c)
- if delta < 0:
- print("the equation: ", a, "x²+", b, "x+", c, "=0 has no real solution")
- elif delta == 0:
- x = b / (2 * a)
- print("the equation: ", a, "x²+", b, "+", c, "=0 has unique solution")
- print("x = ", x)
- elif delta > 0:
- from math import sqrt
- x1 = ((-b + sqrt(delta)) / (2 * a))
- x2 = ((-b - sqrt(delta)) / (2 * a))
- print("X has two value are :")
- print("X = ", x1, " or X = ", x2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement