Exercise 10: How Long Until the Money Doubles? — Possible Solution ==================================================================== start = float(input("Starting balance: ")) rate = float(input("Yearly interest rate (%): ")) balance = start years = 0 while True: balance += balance * rate / 100 years += 1 if balance >= 2 * start: print(f"Doubled after {years} years: {balance:.2f}") break if years == 50: print(f"Still not doubled after 50 years: {balance:.2f}") break Example run: Starting balance: 1000 Yearly interest rate (%): 7 Doubled after 11 years: 2104.85 Second run: a 1% rate hits the 50-year limit: Starting balance: 1000 Yearly interest rate (%): 1 Still not doubled after 50 years: 1644.63 WHY THIS WORKS AS AN ANSWER ------------------------------ Each pass adds one year of interest and counts it. The first break fires when the goal is reached. The second is the safety net: with a rate of 0 or a very small rate the balance might never double, and without it the loop would never end. Both checks come after the update, so the year that crosses the line is included in the count. Checking 'balance >= 2 * start' (and not '==') matters, because the balance almost never lands exactly on double.