Python practice: Indefinite Loops with while & Loop Control

Chapter 8 · 8 questions · included in full access

  1. Question 1 · easy

    Basic while countdown

    Initialize count = 3. While count > 0, print count and subtract 1 each time. Print "Launch!" after the loop:

    Solve it in your browser
  2. Question 2 · easy

    Simulate loan depletion

    Given debt = 1000 and payment = 300, count how many full payments can be made while debt >= payment. Print months:

    Solve it in your browser
  3. Question 3 · easy

    Halt audit with break

    Given txs = [120, 450, 9999, 310], loop through txs. If an amount exceeds 5000, print "Audit frozen!" and break:

    Solve it in your browser
  4. Question 4 · easy

    Skip negative rows with continue

    Given amounts = [100, -20, 300, -50, 400], loop through amounts. If amt < 0, continue. Otherwise add to total = 0. Print total:

    Solve it in your browser
  5. Question 5 · medium

    Interactive loop with sentinel break

    Given commands = ["sync", "export", "quit", "extra"], loop over commands. If cmd == "quit", print "Exited" and break:

    Solve it in your browser
  6. Question 6 · easy

    Threshold goal attainment

    Given deposits = [500, 400, 600, 300, 700] and goal = 1200, accumulate into savings = 0. Stop with break once savings >= goal. Print savings:

    Solve it in your browser
  7. Question 7 · easy

    Prevent infinite loop with counter update

    Fix this while loop so it terminates after 3 iterations: step = 0. While step < 3, print step and increment step += 1:

    Solve it in your browser
  8. Question 8 · medium

    Exponential backoff simulation

    Simulate exponential retry delay: delay = 1. Double delay *= 2 while delay < 16. Print each delay value:

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing