Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Debugging Queue

The following implementation has a bug. (Even though the n was supposed to remove the element and the code seems to mean that it does, we still see two items after we removed the first.)

The question is how to debug this?

q = []

while True:
    name=input("your name: ")

    if name=="n":
        print(q.pop(0))

    if name=="x":
        print(q)
        exit()

    if name=="s":
        print(len(q))
        exit()
    else:
        q.append(name)
        continue

your name: Foo
your name: Bar
your name: n
Foo
your name: s
2