# ============================================================ # AP CSP — LOOPS NOTES 2 — WHILE LOOPS # INDEPENDENT PRACTICE — separate sandbox # ============================================================ # # NAME: # PERIOD: # # JuiceMind sandbox name: AP CSP — Loop Reference Builder — Practice # # DIRECTIONS: # Make a NEW JuiceMind sandbox for this practice (not your notes). # Do the challenges IN ORDER. Each one must run before you start the next. # Use your notes program as your reference — that's what it's for! # The last challenge is FROM SCRATCH: no starter code. # # ============================================================ # CHALLENGE 1 — COUNTDOWN TO ZERO # ============================================================ # Use a while loop to print start down to 0. # Then print "Blast off!" # # TEST IT: # Change start to 3 — your output should be 3 2 1 0 Blast off! start = 7 # your code here # ============================================================ # CHALLENGE 2 — RUNNING TOTAL UNTIL 0 # ============================================================ # Ask for numbers until the user types 0 (the sentinel). # Add each number to total. # Print the total after the loop. # # TEST IT: # Input 4, 6, 0 -> Total: 10 total = 0 # your code here # ============================================================ # CHALLENGE 3 — GUESS THE NUMBER # ============================================================ # Keep asking for a guess while guess is not secret. # Count the guesses with a counter. # After the loop print how many guesses it took. # # TEST IT: # Input 3, 9, 7 -> 3 guesses secret = 7 guess = 0 # your code here # ============================================================ # CHALLENGE 4 — DOUBLING # ============================================================ # Start at 1. Keep doubling the number while it is less than # 1000. # Print each value. # # TEST IT: # Last value printed should be 512 # your code here # ============================================================ # CHALLENGE 5 — FROM SCRATCH — PIN PAD # ============================================================ # The correct PIN is 2468. Give the user at most 3 tries. # Use a while loop with a compound condition (tries left AND not # correct). # Print "Unlocked" or "Locked out" after the loop. # # TEST IT: # Input 1111, 2468 -> Unlocked # Input 1,2,3 -> Locked out # your code here