Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. # Solve the quadratic equation
  2. # ax**2 + bx + c = 0
  3. # a,b,c are provied by the user
  4.  
  5. # import complex math module
  6. import cmath
  7.  
  8. a = float(input('Enter a: '))
  9. b = float(input('Enter b: '))
  10. c = float(input('Enter c: '))
  11.  
  12. # calculate the discriminant
  13. d = (b**2) - (4*a*c)
  14.  
  15. # find two solutions
  16. sol1 = (-b-cmath.sqrt(d))/(2*a)
  17. sol2 = (-b+cmath.sqrt(d))/(2*a)
  18.  
  19. print('The solution are {0} and {1}'.format(sol1,sol2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement