The answersDownload the PDF
Worksheet

0.1 Your first program

Python quick start · Robot club · about 10 min

BugBotLab
NameClassDate

What this lesson is about

The two lines at the top, drive, wait, stop, print, and the rule that stops the robot on its own.

Questions 7 marks in all

  1. [1 mark]What does connect() do?

    1. AGets you the robot, ready to take commands
    2. BBrings in the robot's commands
    3. CStarts the robot driving
    4. DPrints a line under the program
  2. [1 mark]What does forward(50) do on its own?

    1. AStarts the robot at half speed and goes straight on to the next line
    2. BDrives 50 cm and then stops
    3. CDrives for 50 seconds
    4. DWaits until the robot has finished moving
  3. [1 mark]This program has no stop(). What does the robot do?

    from bugbot import *
    connect()
    
    forward(60)
    wait(1.5)
    1. ADrives for about 1.5 seconds, then stops by itself once the program stops sending it commands
    2. BDrives for ever until you close the page
    3. CNever moves, because there is no stop()
    4. DStops straight away, because the program is too short
  4. [1 mark]Put these lines in order to drive forward for two seconds, stop, and then say so.

    Number the lines 1 to 6 to put them in the right order.

    1. connect()
    2. wait(2)
    3. from bugbot import *
    4. forward(50)
    5. print("done")
    6. stop()
  5. [1 mark]What does this program print?

    print("drove for", 2, "seconds")
  6. [1 mark]Which of these make BugBot move across the mat?

    Tick every answer that is true.

    1. Aforward(60)
    2. Bright(60)
    3. Cled("green")
    4. Dbackward(60)
    5. Eprint(position())
  7. [1 mark]You drive forward for 1 second and back for 1 second. Why does position() not say exactly (0, 0)?

    1. ADriving by time is never exact, and the robot leans a little as it goes
    2. BThere is a mistake in the program
    3. Cposition() counts from the middle of the mat
    4. Dbackward() always goes twice as far

The task: cross the line

Drive from the start into the green zone and stop inside it, using forward, wait and stop. If it stops short, wait longer or drive faster.

from bugbot import *
connect()

forward(50)
wait(1)
stop()

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

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

Challenges

  1. Make the light red while the robot drives and green when it stops.
  2. Drive there sideways instead, with right() or left().
  3. Print position() before and after the drive, and work out how far 1 second at speed 50 takes you.