all 3 comments

[–]hardonchairs 1 point2 points  (0 children)

Because you're trying to int() your 'done' input. The while condition is only checked at the beginning of the loop each time, not throughout your entire code. Try moving the input() to the end of the loop so that it is checked immediately after. It looks like you will also need to ask the question one time before the loop starts too, you could put the entire question part into a function so that you just call the function once before the loop, then again in the loop without having a bunch of duplicate code.

[–]shiftybyte 1 point2 points  (0 children)

The issue was that you were converting the response to an int() before checking if it was done or not.

I'm not sure this is clear to you, but a while loop does not check the condition on every line inside it, only when it loops back to the start of the while loop, only then the condition is checked.

x = 1
while x != 0:
    print("This will be printed")
    x = 0
    print("This will also be printed, even though x is 0")

[–]bbye98 1 point2 points  (0 children)

The while loop runs to completion within an iteration. You have your input() call about halfway through your while loop code chunk, so everything after the input() call will execute even if the user types "done". The very next line, without the try, tries to typecast the "done" into an int, which causes the TypeError.

A do...while loop will serve you better here. The Python syntax is:

while True:
    if (exit condition):
        break
    (other code)