import math
def quadratic(a,b,c):
if not isinstance(a,(float,int)) or a ==0:
raise TypeError('a wrong')
if not isinstance(b,(float,int)):
raise TypeError('b wrong')
if not isinstance(c,(float,int)):
raise TypeError('c wrong')
x = math.sqrt(b**2-4*a*c)
if x < 0:
print("无解")
else:
x1 = (-b+x)/(2*a)
x2 = (-b-x)/(2*a)
return x1,x2
厉害,请问第一次看完就就能写出来了吗
Sign in to make a reply
牛顿的烈焰激光剑
import math
def quadratic(a,b,c):
if not isinstance(a,(float,int)) or a ==0:
raise TypeError('a wrong')
if not isinstance(b,(float,int)):
raise TypeError('b wrong')
if not isinstance(c,(float,int)):
raise TypeError('c wrong')
x = math.sqrt(b**2-4*a*c)
if x < 0:
print("无解")
else:
x1 = (-b+x)/(2*a)
x2 = (-b-x)/(2*a)
return x1,x2