Discuss / Python / 交作业啦

交作业啦

Topic source

1ngram4_

#1 Created at ... [Delete] [Delete and Lock User]

import math def quadratic(a,b,c): if not isinstance(a,(int,float)) or not isinstance(b,(int,float)) or not isinstance(c,(int,float)): raise TypeError('bad operand type') d=(bb-(4ac)) if d<0: return ('无解') elif d==0: return ('方程有一个解:%s' %(-b/(2a))) else: x1=(-b+math.sqrt(d))/(2a) x2=(-b-math.sqrt(d))/(2a) return ('方程有两个解:%.2f %.2f' %(x1,x2))


  • 1

Reply