Week 4

Loop-the-Loop

Aim: Make Python repeat commands without typing them again and again.

New coding words

  1. loop
  2. repeat
  3. for
  4. range
  5. indent

What the coding words mean

  1. loop: A part of a program that runs more than once.
  2. repeat: To perform the same action again.
  3. for: A Python word used to start a loop.
  4. range: Gives a loop a sequence of numbers. range(4) makes the loop run four times.
  5. indent: Spaces at the beginning of a line showing that it belongs inside a loop.
Code along

Repeat a dance routine

Use a for loop to repeat two dance commands four times.

Python coding spaceReady to run
.py

Tab indents. Esc then Tab leaves the editor. Ctrl/⌘ + Enter runs your code.

Output (Shell)What your program does
Select Run my code to try this program.
Opening your coding space…Each activity has its own saved code.
Mini project

Robot Dance

Make Python perform a robot dance for three rounds.

Python coding spaceReady to run
.py

Tab indents. Esc then Tab leaves the editor. Ctrl/⌘ + Enter runs your code.

Output (Shell)What your program does
Select Run my code to try this program.
Opening your coding space…Each activity has its own saved code.

Your mini-project to-do list

0 of 3 completed

Complete these activities in the mini-project editor above. After each change, select Run my code to check your program’s output or drawing.

Save your finished mini project

Select Download my work and save the file as week_4_robot_dance.py. The .py ending tells us that the file contains Python code. Keep this file as a copy of your finished program.

Debugging detective

Chi Opara, your course guide

Knowledge check

Question 1
Python coderange(4)

How many times does this run the loop?

Choose one answer
Question 2

Why are the commands inside the loop indented?

Your answers are checked in this browser and are not submitted.

How are you getting on so far?

My checklist

Finished Week 4?

This progress is saved only in this browser.