我正在编写一个代码,生成一个魔方置乱,我使用if scramble:来查看for循环中的列表中是否有任何内容。我不知道如何检查列表索引> 0中是否有任何内容。代码在这里(请不要评判我的编码,这不是最后的,我还有一些代码清理工作,我现在只在做GCSE计算机科学)
scrambling = True
while scrambling:
scramble = []
for i in range(0,30):
while True:
chosen = r.choice(moves)
if scramble:
if scramble[i-1] != chosen:
if chosen[0] != scramble[i-1][0]:
break
else:
pass
else:
pass
else:
break
scramble.append(chosen)
if opposites[scramble[15]] != opposites.get(scramble[16]):
if opposites[scramble[14]] != opposites.get(scramble[15]):
scrambling = False
else:
pass
else:
pass谢谢你的帮助
发布于 2022-04-09 13:58:13
您可以检查列表的长度:
if len(scramble) > 1:
#...https://stackoverflow.com/questions/71808700
复制相似问题