Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cmath
- def compute_roots(a, b, c):
- d = cmath.sqrt(b**2 - 4*a*c)
- x1 = (-b+d) / (2*a)
- x2 = (-b-d) / (2*a)
- return x1, x2
- def quadratic_solver():
- a, b, c = [ float(input(f'{c}: ')) for c in ['A', 'B', 'C'] ]
- if a == 0:
- print('\'A\' can\'t be 0!')
- return
- x1, x2 = compute_roots(a, b, c)
- print(f'x1 = {x1}, x2 = {x2}\n')
- active = input('Enter [y] to start: ') == 'y'
- while active:
- quadratic_solver()
- active = input('Enter [y] to run again: ') == 'y'
- print('Bye bye!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement