# ============================================================ # PROGRAMMING FOUNDATIONS — LOOPS NOTES 1 — FOR LOOPS + RANGE() # GUIDED NOTES — fill in as we code together # ============================================================ # # NAME: # PERIOD: # # JuiceMind sandbox name: Foundations — Loops Notes # # DIRECTIONS: # Write working Python under each set of comments as we go. # Run and test each section BEFORE moving to the next one. # When we finish, the WHOLE file must run clean top to bottom. # If you break something on purpose, comment it back out. # # Exam objective(s): 2.2 # # JOURNAL (answer as a comment before we start): # You need to print 'Hello' 500 times. What's wrong with 500 # print statements? # -> # ------------------------------------------------------------ # STEP 01 — RANGE(STOP) # ------------------------------------------------------------ # ★ NEW TERM — ITERATION: # repeating a set of instructions # ★ NEW TERM — RANGE: # a sequence of integers; the stop value is NOT included # Print 0 through 4 using for and range(5). # PREDICT → TYPE → RUN → MODIFY: Predict: does 5 print? # ------------------------------------------------------------ # STEP 02 — RANGE(START, STOP) # ------------------------------------------------------------ # Print 3 through 8. # PREDICT → TYPE → RUN → MODIFY: Why is the stop 9, not 8? # ------------------------------------------------------------ # STEP 03 — RANGE(START, STOP, STEP) # ------------------------------------------------------------ # ★ NEW TERM — STEP: # how much the loop variable changes each time # Print 2, 4, 6, 8, 10. Then 10 down to 1 with a negative step. # PREDICT → TYPE → RUN → MODIFY: Exam trap: what does range(10, # 0) print? (Nothing!) # ------------------------------------------------------------ # STEP 04 — LOOP OVER A LIST AND A STRING # ------------------------------------------------------------ # Loop over a list of 3 colors, then over the letters of # "python". # PREDICT → TYPE → RUN → MODIFY: How many times does the second # loop run? # ------------------------------------------------------------ # STEP 05 — ACCUMULATOR AND COUNTER # ------------------------------------------------------------ # ★ NEW TERM — ACCUMULATOR: # a variable that collects a running total # Total 1 through 100. Count how many numbers 1–50 are divisible # by 7. # PREDICT → TYPE → RUN → MODIFY: Predict both answers before # running. # ============================================================ # WRAP-UP (answer as comments) # ============================================================ # CONNECTION: Exam objective 2.2: construct and analyze code # that performs iteration. Expect 'what is the output?' and 'how # many times does this run?' items. # 1. In your own words, what does each NEW TERM mean? # -> # 2. Which step surprised you, and why? # ->