python中关于循环的一些编写程序问题

img


aList = [-1, -4, 6, 7, 3, 9, -11]
lis1 = [i for i in aList if i>=6 and i<9]
print(lis1)

lis2 = []
for i in aList:
    if i >= 6 and i < 9:
        lis2.append(i)
print(lis2)

lis3 = []
while aList != []:
    li = aList.pop()
    if li >= 6 and li < 9:
        lis3.append(li)
print(lis3)

如果有用望采纳

first

return [x for x in alist if x>=6 and x<9]

second

new_list = []
for x in alist:
if x>=6 and x<9 :
new_list.append(x)
return new_list

third

n = 0
new_list = []
while alist[n]>=6 and alist[n]<9 :
new_list.append(alist[n])
n = n+1
if n >= len(alist):
break
return new_list
#如果有不对的,欢迎大家指点。万分感谢!