擅长:python、mysql、java
<p>我认为您的问题在于将for循环与队列.删除()功能。似乎<code>for x in queue:</code>操作符在运行时编辑列表时遇到了问题。我建议改为使用<code>while queue:</code>,并将x设置为第一个元素。你知道吗</p>
<pre><code> while queue:
x = queue[0]
print("The elevator's doors are closed and it's moving to floor:",x)
floor = str(x)
print("...")
print()
print("The elevator has arrived on floor "+floor+", and the doors are open.")
queue.remove(x)
addFloor = int(input("Floor to call the elevator to: "))
if addFloor > 10 or addFloor < 1:
raise Exception(str(addFloor)+" is not a valid floor.")
print(queue)
if floorCompare(int(floor), int(queue[0]), int(addFloor)) == True:
print("The elevator can hit this stop en route to its next one.")
else:
print("The elevator must hit this stop separately.")
</code></pre>