Section 6.3 For Loop Range
Subgoals for Evaluating a Loop.
Subsection 6.3.1
Problem: Given the following code, what is the output?
total = 0
for x in range(5, 50):
if x % 5 == 0:
total += x
print(total)
Subsection 6.3.2 Determine loop components
Starting values: The initial value in x will be 5.
total = 0
Iteration Variable: The iteration variable x will be increased by 5 every iteration.
Termination condition: When x is 50
Body that is repeated based on indentation:
if x % 5 == 0:
total += x
Subsection 6.3.3 Trace the loop, writing updated values for every iteration or until you identify the pattern
For every iteration of loop, write down values.



You have attempted 1 of 1 activities on this page.