The answersDownload the PDF
Worksheet

0.3 Doing it again

Python quick start · Robot club · about 12 min

BugBotLab
NameClassDate

What this lesson is about

for and while, indentation, and a square drawn with three lines instead of eight.

Questions 7 marks in all

  1. [1 mark]What does this program print?

    for i in range(4):
        print("this is time number", i)
  2. [1 mark]What does this program print?

    for i in range(3):
        print("side")
    print("done")
  3. [1 mark]What does this program print?

    for i in range(3):
        print(i * 10)
  4. [1 mark]What does this program make the robot do?

    for i in range(4):
        forward(50, distance=25)
        turn_right(35, angle=90)
    stop()
    1. ADrive a square, turning clockwise, and finish near where it started
    2. BDrive one straight line 100 cm long
    3. CDrive a triangle
    4. DDrive a square, turning anticlockwise
  5. [1 mark]You want the robot to drive a triangle with equal sides. How many degrees should turn_right turn at each corner?

  6. [1 mark]The robot starts at heading 0 and runs turn_right(35, angle=90) three times. Ignoring small errors, what does heading() say? Give a whole number of degrees.

  7. [1 mark]Why does a while loop that drives need a small wait() inside it?

    1. ASo time passes and the robot moves between looks; without it the loop spins as fast as it can
    2. BTo make the robot drive more slowly
    3. CPython gives an error for any loop without a wait
    4. DSo that clock() can start counting

The task: four corners

Drive a square: 30 cm a side, turning right at each corner, using a for loop. The four green squares are the corners it has to pass through.

from bugbot import *
connect()

for i in range(4):
    # one side and one corner
    forward(50, distance=30)

stop()

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/start-3-loops/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Make the square go anticlockwise with turn_left.
  2. Flash the light: for loop, led("red"), wait(0.2), led("off"), wait(0.2).
  3. Drive a triangle. What angle does each corner need?