# 关于return语句的诡异事件

0
[已解决问题] 解决于 2018-02-02 16:25
```def search(num,seq=[]):
if len(seq)==1:
#      print("3")
#        assert seq[0]==num
#       num1=seq[0]
return seq[0]
elif num<seq[len(seq)//2]:
#       print("2")
seq=seq[0:len(seq)//2]
search(num,seq=seq[:])
return 2
elif num > seq[len(seq)//2]:
#      print("1")
seq=seq[len(seq)//2+1:]
search(num,seq=seq[:])
else:
#     print("5")
return seq[len(seq)//2]
def test(seq):
return 2
seq=[1,2,3,4,5,6,7,8]
seq.sort()
print(search(6,seq=seq[:]))
print(seq)
print(test(seq))```
```None
[1, 2, 3, 4, 5, 6, 7, 8]
2```

0

```def search(num,seq=[]):
if len(seq)==1:
return seq[0]
elif num<seq[len(seq)//2]:
seq=seq[0:len(seq)//2]
return search(num,seq=seq[:])
elif num > seq[len(seq)//2]:
seq=seq[len(seq)//2+1:]
return search(num,seq=seq[:])
else:
return seq[len(seq)//2]
def test(seq):
return 2
seq=[1,1,2,3,4,5,6,7,8]
seq.sort()
print(search(6,seq=seq[:]))
print(seq)
print(test(seq))```

```def search(num,seq=[]):
mid=len(seq)//2
if len(seq)==1:
return 0
elif num<seq[mid]:
return mid+search(num,seq=seq[0:mid])
elif num > seq[mid]:
return mid+search(num,seq=seq[mid+1:])
else:
return mid
def test(seq):
return 2
seq=[1,1,2,3,4,5,6,7,8]
seq.sort()
print(search(6,seq=seq[:]))
print(seq)
print(test(seq))```

akisann | 菜鸟二级 |园豆：341 | 2018-01-31 17:15

您需要登录以后才能回答，未注册用户请先注册