有意外的缩进
import math def quadratic_equation(a, b, c): t = b**2 - 4*a*c if a == 0 or t < 0: return '无解' elif t == 0: x1 = -b/2*a return '有唯一解',x1 else: x1 = (-b + math.sqrt(t))/(2*a) x2 = (-b - math.sqrt(t))/(2*a) return x1,x2 print quadratic_equation(2, 3, 0) print quadratic_equation(1, -6, 5)
提示
if a == 0 or t < 0:
^
IndentationError: unexpected indent
看起来是正常的,把if、elif、else前的Tab换成四个空格就好了,为什么会有意外缩进产生呢?