[{"metadata":{"trusted":true,"scrolled":true},"cell_type":"code","source":"import math\n \ndef quadratic(a, b, c): # ax**2+bx+c=0\n \n if a == 0:\n \n return x == -c/b\n \n elif (b**2)-(4*a*c) >= 0:\n \n d = (b**2)-(4*a*c)\n \n e = math.sqrt(d)\n \n x1 = (-b-e)/(2*a)\n x2 = (-b+e)/(2*a)\n \n return x1,x2\n else:\n print('无解')\n\na = quadratic(1, 9, 3)\n\nprint(a)","execution_count":24,"outputs":[{"output_type":"stream","text":"(-8.653311931459037, -0.34668806854096257)\n","name":"stdout"}]}]
import math
def quadratic(a, b, c): # ax**2+bx+c=0
if a == 0:
return x == -c/b
elif (b**2)-(4*a*c) >= 0:
d = (b**2)-(4*a*c)
e = math.sqrt(d)
x1 = (-b-e)/(2*a)
x2 = (-b+e)/(2*a)
return x1,x2
else:
print('无解')
a = quadratic(1, 9, 3)
print(a)
Sign in to make a reply
小尾巴翘123
import math
def quadratic(a, b, c): # ax**2+bx+c=0
if a == 0:
return x == -c/b
elif (b**2)-(4*a*c) >= 0:
d = (b**2)-(4*a*c)
e = math.sqrt(d)
x1 = (-b-e)/(2*a)
x2 = (-b+e)/(2*a)
return x1,x2
else:
print('无解')
a = quadratic(1, 9, 3)
print(a)