def quar(a,b,c): if not isinstance(a,(int,float))|isinstance(b,(int,float))|isinstance(c,(int,float)): raise TypeError(‘Wrong Type inputing!‘) else: from math import sqrt tmp1=b**2-4*a*c if tmp1>0: return ‘%.04f‘%float((-b+sqrt(tmp1))/(2*a)),‘%.04f‘%((-b-sqrt(tmp1))/(2*a)) elif tmp1==0: return -b/(2*a) else: return ‘No rational answer!‘
时间: 2024-10-10 01:34:14