Exercise 5: Average of Numbers Until the User Types done — Possible Solution ==================================================================== total = 0 count = 0 while True: entry = input("Enter a number (or done): ") if entry == "done": break total += float(entry) count += 1 if count == 0: print("No numbers entered") else: print(f"Count: {count} Sum: {total} Average: {total / count:.2f}") Example run: Enter a number (or done): 10 Enter a number (or done): 20 Enter a number (or done): 5 Enter a number (or done): done Count: 3 Sum: 35.0 Average: 11.67 Second run: done typed immediately: Enter a number (or done): done No numbers entered WHY THIS WORKS AS AN ANSWER ------------------------------ You cannot know in advance how many numbers the user will type, so a for loop does not fit and the loop has to be while True with its own exit. The sentinel check comes first, before float(), because float('done') would raise ValueError. After the loop, count == 0 is the case where break fired on the very first pass; dividing by count there would raise ZeroDivisionError, so it is handled separately.