function
def tt(a,b):
trend = []
if b == 0 or b == 3 or b == 7 or b == 4 or (a == 0 or a ==1 or a == 5 and b == 2) or (a == 5 and b == 6):
trend.append(1)
elif b == 5 or (a ==2 or a ==3 or a ==4 and b == 6) or (a != 5 and b == 1):
trend.append(-1)
elif (a == 3 or a == 4 or a == 6 or a == 7 and b ==2) or (a == 0 or a == 1 or a == 7 and b == 6) or (a == 5 and b == 1):
trend.append(0)
else:
trend.append(0)
return trend
tt = tt(2,2)
tt
结果:[-1]
问题:
会进入执行这一条
elif b == 5 or (a ==2 or a ==3 or a ==4 and b == 6) or (a != 5 and b == 1):
trend.append(-1)
因为执行到a == 2就直接进入了…
但本来的意思是:当a == 2 且 b == 6 时才执行阿…
改成这样:
def tt(a,b):
trend = []
if b == 0 or b == 3 or b == 7 or b == 4 or (a == 0 or a ==1 or a == 5 and b == 2) or (a == 5 and b == 6):
trend.append(1)
###
### 写的详细具体,没有歧义
elif b == 5 or (a ==2 and b == 6) or (a ==3 and b == 6) or (a ==4 and b == 6) or (a != 5 and b == 1):
trend.append(-1)
elif (a == 3 or a == 4 or a == 6 or a == 7 and b ==2) or (a == 0 or a == 1 or a == 7 and b == 6) or (a == 5 and b == 1):
trend.append(0)
else:
trend.append(0)
return trend
tt = tt(2,2)
tt
结果:[0]