我试图取两个随机整数,然后将相应编号的东西从列表中切出,但是我不确定我应该做什么。它说 [r1:r2] 中的冒号不正确。
from random import*
#2
z=['cats','dogs','soccer','weather','whale','tennis']
def slicer(ls):
r1=randrange(0,5)
r2=randrange(0,5)
for x in ls:
[r1:r2]
return('The slice from '+str(r1)+' to '+str(r2)+' is: ' + ls)
print(slicer(z))