Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module: quardic-equation-anshih.py
- from quardic import calculateQuardic
- calculateQuardic(2,4,6)
- -------------------------------------------
- quardic.py
- import cmath
- # function to check for
- # solutions of equations
- def calculateQuardic(a, b, c):
- if (a == 0):
- print('Value of a cant be 0')
- return ()
- d = b ** 2 - 4 * a * c # discriminant
- if d < 0:
- print("This equation has no real solution")
- elif d == 0:
- x = (-b + cmath.sqrt(b ** 2 - 4 * a * c)) / 2 * a
- print("This equation has one solutions: "), x
- else:
- x1 = (-b + cmath.sqrt((b ** 2) - (4 * (a * c)))) / (2 * a)
- x2 = (-b - cmath.sqrt((b ** 2) - (4 * (a * c)))) / (2 * a)
- print("This equation has two solutions: ", x1, " or", x2)
- if __name__ == "__main__":
- a, b, c = -2, 4, 3
- calculateQuardic(a, b, c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement