def quadratic(a, b, c=0):
mt = (a, b, c)
for num in mt:
if isinstance(num, (int, float)):
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)
if x1 == x2:
x = x1
else:
x = (x1, x2)
x = 'no result'
x = '请输入正确的格式'
return x
a = eval(input('x^2的系数:'))
b = eval(input('x的系数: '))
c = eval(input('常数:'))
x = quadratic(a, b, c)
print('方程的解为:{}'.format(x))
Sign in to make a reply
微尘初心
def quadratic(a, b, c=0):
mt = (a, b, c)
for num in mt:
if isinstance(num, (int, float)):
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)
if x1 == x2:
x = x1
else:
x = (x1, x2)
else:
x = 'no result'
else:
x = '请输入正确的格式'
return x
a = eval(input('x^2的系数:'))
b = eval(input('x的系数: '))
c = eval(input('常数:'))
x = quadratic(a, b, c)
print('方程的解为:{}'.format(x))