Skip to content

Year 8 · Computing · Python: loops · Lesson 3

Totals, counters and loops with if

Python loops with running totals, counters, the modulo operator and if statements inside loops, including a simple quiz program.

Whiteboard video lesson: Totals, counters and loops with if

20-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What your child will learn

  • Build a running total
  • Use a counter
  • Use % to find remainders
  • Combine loops and if statements
  • Predict program output

The method

  1. Set the variable to 0 before the loop.
  2. Add the value (total) or 1 (counter).
  3. Use if to choose when.
  4. Print after the loop.

Key words: running total, counter, modulo, if, +=, accumulator, indentation.

Worked examples

The first three practice questions from the lesson, with every step.

Question 1

What should a running total start at?

  1. Step 1: Before anything is added

Answer: 0

Question 2

Where should total = 0 go: inside or before the loop?

  1. Step 1: Inside would reset it every time

Answer: Before the loop

Question 3

What is 10 % 3?

  1. Step 1: 10 ÷ 3 = 3 remainder 1

Answer: 1