Skip to main content

Section 6.4 Evaluate Loops-WE2-P1

Subgoals for Evaluating a Loop.

  1. Determine Loop Components
    1. Start condition and values
    2. Iteration variable and/or update condition
    3. Termination/final condition
    4. Body that is repeated based on indentation
  2. Trace the loop, writing updated values for every iteration or until you identify the pattern

Subsection 6.4.1 Evaluate Loops-WE2-P1

Exercises Exercises

5.
Q10: After the following code is executed:
a = 0
b = 0
for x in range(1, 15):
    if x % 2 == 0:
        a += x
    else:
        b += x
The value of a is and the value of b is
You have attempted of activities on this page.