|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 zltzlt 于 2020-4-18 13:11 编辑
- list01 = [34,5,6,78,9,0,5,8,88,4]
- list02 = list01
- while True:
- if list02[0] > list02[1]:
- del list02[1]
- else:
- if list02[0] == list02[1]:
- del list02[1]
- else:
- list02[0] = list02[1]
- print(list02[0])
复制代码
你没有退出循环的条件,这样改改:
- list01 = [34,5,6,78,9,0,5,8,88,4]
- list02 = list01
- while len(list02)>1: #list2只剩下1个元素的时候退出
- if list02[0] > list02[1]:
- del list02[1]
- else:
- if list02[0] == list02[1]:
- del list02[1]
- else:
- list02[0] = list02[1]
- print(list02[0])
复制代码
|
|