Quadratic equation solutions programe

Programe is:
#
#  Quadratic equation solutions programe
#  a*x**2 + b*x + c = 0
#
import cmath
answer = 'y'
while answer == 'y' or answer == 'Y':
    a = float(input(' coeficient a is:'))
    b = float(input(' coeficient b is:'))
    c = float(input(' coeficient c is:'))
    gama = 2*a
    eta = -b/gama
    delta = cmath.sqrt(b*b - 4*a*c)/gama
    x_1 = eta - delta
    x_2 = eta + delta
    print('The solution X1 is:', x_1)
    print('The solution X2 is:', x_2)
    answer = input(' If you want to continue, type y or Y: ')
print(' Thank you for working with this program!')

Results are:
============ RESTART: /Users/ionivan/Documents/QuadraticEcuation.py ============
 coeficient a is:1
 coeficient b is:1
 coeficient c is:1
The solution X1 is: (-0.5-0.8660254037844386j)
The solution X2 is: (-0.5+0.8660254037844386j)
 If you want to continue, type y or Y: y
 coeficient a is:1
 coeficient b is:5
 coeficient c is:6
The solution X1 is: (-3+0j)
The solution X2 is: (-2+0j)
 If you want to continue, type y or Y: 1
 Thank you for working with this program!


(March 31, 2022)

Comments

Popular posts from this blog

Pointers in PYTHON?

Generates M prime numbers