def Task4():
import random
t = True
list1 = []
list2 = []
rand = random.randint(1,6)
list1.append(rand)
print(list1)
for x in range(0,5):
if list1[0] == (rand):
list1.pop(0)
else:
list2.append(rand)
print(list2)
list1.pop(0)
无法理解为什么
if list1[0] == (rand)
会一直出现“列表索引超出范围”的错误。
if list1 and list1[0] == rand
- grc