Discuss / Python / 交作业啦。

交作业啦。

Topic source

import math

def qua(a,b,c):

for i in (a,b,c):

if not isinstance(i,(int,float)):

  raise TypeError('please enter number')

e=b*b-4*a*c

if e<0 or a==0:

 raise TypeError('no answer')

else:

 print('the number you entered meet requirement')

 x1=(-b+math.sqrt(e))/2/a

 x2=(-b-math.sqrt(e))/2/a

 if x1==x2:

 print('only one answer:%.2f'%x1)

 else:

 print('have two answer:%.2f,%.2f'%(x1,x2))


  • 1

Reply