Advertisement
ToSemIdeia

Resolve equação do segundo grau

May 24th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import math
  2. import time
  3.  
  4. print('ax^2 + bx + c = 0')
  5. print('Considerando a equação de segundo grau acima, dê os valores de: ')
  6. a = float(input('a -> '))
  7. b = float(input('b -> '))
  8. c = float(input('c -> '))
  9.  
  10. d = b ** 2 - 4 * a * c
  11. x1 = (-b + math.sqrt(d)) / 2 * a
  12. x2 = (-b - math.sqrt(d)) / 2 * a
  13. print('-'*50)
  14. print('CALCULANDO AS RAÍZES DE: {}x^2 + {}b + {}'.format(a, b, c))
  15. print('-'*50)
  16. time.sleep(3)
  17.  
  18. if x1 == x2:
  19.     print('r = {:.2f}'.format(x1))
  20. else:
  21.     print('r1 = {:.2f} \nr2 = {:.2f}'.format(x1, x2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement