DeukausGames

Equação 2 grau

Aug 11th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import cmath
  2. # Resolução equação segundo grau
  3.  
  4. def solvequadeq(a, b, c): # funcao equacao 2* grau
  5.     D = b**2 - 4 * a * c
  6.     x1 = (-b - cmath.sqrt(D)) / (2 * a)
  7.     x2 = (-b + cmath.sqrt(D)) / (2 * a)
  8.     return x1, x2
  9.  
  10. #a*x**2 + b*x + c
  11. a = int(input('A = a.x^2'))
  12. b = int(input('B = b.X'))
  13. c = int(input('C = c'))
  14.  
  15. print('Equacão: {}*x**2 + {}*x + {} = 0'.format(a, b, c))
  16. solutions = solvequadeq(a, b, c)
  17. print('Respostas :')
  18. print('x1 = %s' % solutions[0])
  19. print('x2 = %s' % solutions[1])
Advertisement
Add Comment
Please, Sign In to add comment