Python practice: Indefinite Loops with while & Loop Control
Chapter 8 · 8 questions · included in full access
Question 1 · easy
Basic while countdown
Solve it in your browserInitialize
count = 3. Whilecount > 0, printcountand subtract 1 each time. Print"Launch!"after the loop:Question 2 · easy
Simulate loan depletion
Solve it in your browserGiven
debt = 1000andpayment = 300, count how many full payments can be made whiledebt >= payment. Printmonths:Question 3 · easy
Halt audit with break
Solve it in your browserGiven
txs = [120, 450, 9999, 310], loop throughtxs. If an amount exceeds5000, print"Audit frozen!"andbreak:Question 4 · easy
Skip negative rows with continue
Solve it in your browserGiven
amounts = [100, -20, 300, -50, 400], loop through amounts. Ifamt < 0,continue. Otherwise add tototal = 0. Printtotal:Question 5 · medium
Interactive loop with sentinel break
Solve it in your browserGiven
commands = ["sync", "export", "quit", "extra"], loop over commands. Ifcmd == "quit", print"Exited"andbreak:Question 6 · easy
Threshold goal attainment
Solve it in your browserGiven
deposits = [500, 400, 600, 300, 700]andgoal = 1200, accumulate intosavings = 0. Stop withbreakoncesavings >= goal. Printsavings:Question 7 · easy
Prevent infinite loop with counter update
Solve it in your browserFix this while loop so it terminates after 3 iterations:
step = 0. Whilestep < 3, printstepand incrementstep += 1:Question 8 · medium
Exponential backoff simulation
Solve it in your browserSimulate exponential retry delay:
delay = 1. Doubledelay *= 2whiledelay < 16. Print eachdelayvalue:
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing