我這代碼一直提示縮進問題,崩潰了
import math
def quadratic_equation(a, b, c):
? ? t = b*b - 4*a*c?
? ? if t >=0:
? ? ? ?x1= (math.sqrt(t)+ b)/(-2*a)
? ? ? ?x2= (math.sqrt(t)- b)/(2*a)
? ? ? ? if x1 == x2:
? ? ? ? ?return 'x1=x2=',x1
? ? ? ? else:
? ? ? ? ? ?return 'x1=',x1,'x2=',x2
? ? else:
? ??
? ? ? ? return 'quadratic wrong')
print quadratic_equation(2, 3, 6)
print quadratic_equation(1, -6, 5)
2018-07-16
同一代碼塊對齊,比如if條件滿足的情況下下要執行的代碼塊。不同代碼塊縮進4個空格
if t >=0:
----x1= (math.sqrt(t)+ b)/(-2*a)
#----? ? 一定要敲四個空格
2018-07-16
#你試試下面這代碼? Python對縮進是很嚴格的 以4個空格表示不同的層級關系
import math
def quadratic_equation(a, b, c):
? ? t = b*b - 4*a*c?
? ? if t >=0:
? ? ? ? x1= (math.sqrt(t)+ b)/(-2*a)
? ? ? ? x2= (math.sqrt(t)- b)/(2*a)
? ? ? ? if x1 == x2:
? ? ? ? ? ? return 'x1=x2=',x1
? ? ? ? else:
? ? ? ? ? ? return 'x1=',x1,'x2=',x2
? ? else:
? ? ? ? return 'quadratic wrong'
print quadratic_equation(2, 3, 6)
print quadratic_equation(1, -6, 5)