求一元二次方程的解

时间:2021-09-20 16:09:27

import math
while True:
a = float (raw_input('input a:'))
b = float (raw_input('input b:'))
c = float (raw_input('input c:'))
if a!=0:
delta=b**2-4*a*c
if delta<0:
print'NO solution'
elif delta==0:
s=-b/(2*a)
print s
else:
root=math.sqrt(delta)
s1=(-b+root)/(2*a)
s2=(-b-root)/(2*a)
print 'Two distinct solutions are:',s1,s2
ch=raw_input('quit?')
if ch=='q':
break