animals=["zebras", "dogs", "cats", "snakes", "insects"]
A=0
B=1
while B<= (len(animals)-1):
if animals[A] > animals[B]:
animals= [animals[B]] + [animals[A]] + animals[B+1:]
B= B + 1
print(B)
print(animals)
print("test- Will this not print as well?")
Okay thanks, that's seems to have worked. I do have one question still, however: how come it printed B but not the next print statement: print(animals)? When I comment out the print B statement then the print(animals) works.
this is the output I get when I run the code (as is) with the while loop not terminating.
output: 2
它不会打印,因为你永远卡在while循环中
第一次运行时,它将检查
如果这是真的,它就会打印出来
再说一遍
同样正确,指纹
然后就开始了
但当它现在试图检查动物[0]>;动物[3],它得到问题,返回False,因为动物[3]不存在。因此你的无限循环
相关问题 更多 >
编程相关推荐