关于用Python解方程问题

要求是这样的

img


结果显示第十行的代码unexpected indent
这是我的代码
def root2(a, b, c):
if a == 0:
print('no real solution')
else:
delta = bb - 4ac
if delta < 0:
print('no real solution')
else:
d = pow(delta, 0.5)
x1, x2 = (-b+d)/(2
a), (-b-d)/(2*a)
print('x1 = %.03f'%x1)
print('x2 = %.03f'%x2)
运行是错误的 我问了其他同学 他们用了其他方法运行出来都是答案部分正确,是哪里漏了嘛?
下面是我同学写的代码:
import math
a,b,c=input('').split()

if bb-4ac < 0:
print("no real solution")
elif b*b-4*a*c > 0:
x1 = (-b-math.sqrt(b
b-4ac))/2a
x2 = (-b+math.sqrt(b
b-4ac))/2a
print("x1={:.3f}\nx2={:.3f}".format(x1,x2))
else:
x =-b/2
a
print("x={:.3f}".format(x))


a,b,c = input().split()
a = int(a)
b = int(b)
c = int(c)
num1 = b ** 2 - 4 * a * c
if a == 0 and b == 0:
    print("Date error")
elif a != 0 and b != 0:
    if num1 < 0:
        print("no real solution")
    elif num1 == 0:
        x = -b / (2 * a)
        print(f"{x:.3f}")
    else:
        x1 = (-b + num1 ** 0.5) / (2 * a)
        x2 = (-b - num1 ** 0.5) / (2 * a)
        print(f"x1={x1:.3f}\nx2={x2:.3f}")
else:
    x = -c / b
    print(f"x={x:.3f}")


看看是不是缩进问题

你的代码里定义了函数root,但是在测试系统里可能不会调用root,所以出错。
你同学的代码没抄全吧?input得到的都是字符串,要转化成数字才能进行后面的计算。