Python quick start · Robot club · about 10 min
Variables, arithmetic, and driving an exact distance instead of counting seconds.
[1 mark]What does this program print?
speed = 60
seconds = 1.5
print("drove at", speed, "for", seconds, "seconds")drove at 60 for 1.5 seconds
Once a variable has a value, its name stands for that value. print shows the values, not the names.
[1 mark]What does this program print?
cm_per_second = 18
seconds = 2
print("that should be about", cm_per_second * seconds, "cm")that should be about 36 cm
* means times. Python works out 18 times 2 before printing it.
[1 mark]What does this program print?
speed = 60
speed = 25
print("speed is", speed)speed is 25
A variable holds one value at a time. The second line replaces 60 with 25, so 25 is what gets printed.
[1 mark]What does distance=20 mean in forward(50, distance=20)?
distance=20 is how far, in centimetres. Naming the argument makes it clear which number is which.[1 mark]Do you need a wait() after forward(50, distance=20)?
wait() is for commands like forward(50) that return straight away.[1 mark]What does this program print?
travelled_cm = 85
print("that is", travelled_cm / 100, "metres")that is 0.85 metres
/ divides. There are 100 centimetres in a metre, so 85 cm is 0.85 metres.
[1 mark]The robot covers 18 cm every second. How many centimetres does it cover in 2.5 seconds? Give the exact number.
Drive 40 cm forward, then 45 cm to the right, and stop in the green zone. Use distance= rather than counting seconds, and give the two distances names at the top.
from bugbot import * connect() first = 40 # your second distance here forward(50, distance=first) stop()
The hint students can ask for: Forward moves you up the mat, right moves you across it. Both take distance= in centimetres.
from bugbot import * connect() first = 40 second = 45 forward(50, distance=first) right(50, distance=second) stop()
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.