Discuss / Python / Answer

Answer

Topic source

留白A_Z

#1 Created at ... [Delete] [Delete and Lock User]
  if not isinstance(a,(int,float))|isinstance(b,(int,float))|isinstance(c,(int,float)):
    print('参数类型错误')
    return 0
  if (b**2-4*a*c)>0:
    x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)
    x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)
  else:
    print('方程无解')
  if x1==x2:
    print('方程只有一个解')
    return x1
  else:
    print('方程有两个解')
    return x1,x2


  • 1

Reply