import math
def quadratic(a,b,c):
s = float (b**2 - 4*a*c)
while a != 0:
if s > 0:
x1 = (-b + math.sqrt(s))/(2*a)
x2 = (-b - math.sqrt(s))/(2*a)
return x1,x2
elif s == 0:
x = (-b)/(2*a)
return x
else:
return "无实数解"
while a == 0:
x = -c/b
a=float(input('请输入a值:'))
b=float(input('请输入b值:'))
c=float(input('请输入c值:'))
print('解为',quadratic(a,b,c))
Sign in to make a reply
在下才是咸鱼
import math
def quadratic(a,b,c):
s = float (b**2 - 4*a*c)
while a != 0:
if s > 0:
x1 = (-b + math.sqrt(s))/(2*a)
x2 = (-b - math.sqrt(s))/(2*a)
return x1,x2
elif s == 0:
x = (-b)/(2*a)
return x
else:
return "无实数解"
while a == 0:
x = -c/b
return x
a=float(input('请输入a值:'))
b=float(input('请输入b值:'))
c=float(input('请输入c值:'))
print('解为',quadratic(a,b,c))