Advertisement
JustMark

Untitled

Jan 26th, 2022
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. import cmath
  2.  
  3. def compute_roots(a, b, c):
  4.     d = cmath.sqrt(b**2 - 4*a*c)
  5.     x1 = (-b+d) / (2*a)
  6.     x2 = (-b-d) / (2*a)
  7.     return x1, x2
  8.        
  9.  
  10. def quadratic_solver():
  11.     a, b, c = [ float(input(f'{c}: ')) for c in ['A', 'B', 'C'] ]
  12.    
  13.     if a == 0:
  14.         print('\'A\' can\'t be 0!')
  15.         return
  16.    
  17.     x1, x2 = compute_roots(a, b, c)
  18.     print(f'x1 = {x1}, x2 = {x2}\n')
  19.  
  20.  
  21. active = input('Enter [y] to start: ') == 'y'
  22. while active:
  23.     quadratic_solver()
  24.     active = input('Enter [y] to run again: ') == 'y'
  25.    
  26. print('Bye bye!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement