Discuss / Python / 交作业

交作业

Topic source

n

#1 Created at ... [Delete] [Delete and Lock User]
# 平方根def quadratic(a,b,c):    if not isinstance(a,(int,float)):        raise TypeError("bad operand type")    if not isinstance(b,(int,float)):        raise TypeError("bad operand type")    if not isinstance(c,(int,float)):        raise TypeError("bad operand type")    # 判断是否有解    n = b*b-4*a*c    if n>0:        x1 = (((-b)+math.sqrt(n))/(2*a))        x2 = (((-b)-math.sqrt(n))/(2*a))        return  "两个解",x1,x2    elif n==0:        x1 = (((-b)+math.sqrt(n))/(2*a))        return "唯一解",x1    else:        return "无解"

  • 1

Reply