Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import sys
  2. import math
  3.  
  4. # ax^2 + bx + c = 0
  5. # x = -b +/- sqrt(b^2 - 4ac) / 2a
  6. # bx + c = 0
  7.  
  8. a = int(input('Enter the value of A (int only): '))
  9. b = int(input('Enter the value of B (int only): '))
  10. c = int(input('Enter the value of C (int only): '))
  11.  
  12. descriminant =  (b * b) - (4 * (a * c))
  13. denominator = (2 * a)
  14.  
  15. if a == 0:
  16.     lineareq = (-c / b)
  17.     print(lineareq)
  18.     exit = input('Press any key to exit.')
  19.     sys.exit()
  20.  
  21. if descriminant > 0:
  22.     result1 = (-b + math.sqrt(descriminant)) / denominator
  23.     result2 = (-b - math.sqrt(descriminant)) / denominator
  24.     print('Your results are: ')
  25.     print(result1)
  26.     print(result2)
  27.  
  28. elif descriminant == 0:
  29.     result1 = (-b + math.sqrt(descriminant)) / denominator
  30.     print('Your result is: ')
  31.     print(result1)
  32.  
  33. else:
  34.     real = (-b / denominator)
  35.     imag = (math.sqrt(-descriminant)) / denominator
  36.     print(real)
  37.     print(imag)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement