Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- # ax^2 + bx + c = 0
- # x = -b +/- sqrt(b^2 - 4ac) / 2a
- # bx + c = 0
- a = int(input('Enter the value of A (int only): '))
- b = int(input('Enter the value of B (int only): '))
- c = int(input('Enter the value of C (int only): '))
- descriminant = (b * b) - (4 * (a * c))
- denominator = (2 * a)
- if a == 0:
- lineareq = (-c / b)
- print(lineareq)
- exit = input('Press any key to exit.')
- sys.exit()
- if descriminant > 0:
- result1 = (-b + math.sqrt(descriminant)) / denominator
- result2 = (-b - math.sqrt(descriminant)) / denominator
- print('Your results are: ')
- print(result1)
- print(result2)
- elif descriminant == 0:
- result1 = (-b + math.sqrt(descriminant)) / denominator
- print('Your result is: ')
- print(result1)
- else:
- real = (-b / denominator)
- imag = (math.sqrt(-descriminant)) / denominator
- print(real)
- print(imag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement