Skip to main content

Section 6.10 Evaluate Loops-WE5-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.10.1 Evaluate Loops-WE5-P1

All of the following problems use the same setup, but they are independent of each other.
high_numbers = [300, 200, 100, 400, 500, 300]
low_numbers = [1, 3, 2, 4, 5, 3]
mixed_numbers = [5, 3, -4, 7, 2]

Exercises Exercises

1.
Q21: What is the output of the following loop?
total = 0
for number in high_numbers:
    total = total + number // 100
print(total)
2.
Q22: What is the output of the following loop?
total = 0
for number in high_numbers:
    total = total + 100
print(total)
3.
Q23: What is the output of the following loop?
combined = ""
for number in low_numbers:
    combined = combined + str(number)
print(combined)
4.
Q24: What is the output of the following loop?
max = 0
for number in low_numbers:
    if number > max:
        max = number
print(max)
5.
Q25: What is the output of the following loop?
sum = 0
for number in high_numbers:
    sum += number
print(sum / len(high_numbers))
You have attempted 1 of 3 activities on this page.