Python quick start · Robot club · about 12 min
def, parameters and return: naming a piece of work so the program reads like what it does.
[1 mark]What happens when Python reads the def side(): lines?
[1 mark]What does this program print?
def side():
print("drive")
print("turn")
side()
side()[1 mark]What does this program print?
def hello():
print("hello")
print("start")[1 mark]What does this program print?
def side(cm):
print("forward", cm)
def square(cm):
for i in range(4):
side(cm)
square(20)[1 mark]What does this program print?
def gap_now(reading):
return round(reading)
print("the gap is", gap_now(27.6), "cm")[1 mark]In def side(cm):, what is cm called?
[1 mark]Why is it worth putting a square into a square(cm) function? Choose all that apply.
Tick every answer that is true.
Write a function leg(cm) that drives that far forward and then turns right, and use it twice to walk the robot through both green squares: 40 cm, corner, 30 cm.
from bugbot import *
connect()
def leg(cm):
# drive, then turn
forward(50, distance=cm)
leg(40)
stop()Plan your program here, then type it in and press Run.
flash() function that blinks the light, and call it at each corner.leg a second parameter for the speed: leg(40, 30).triangle(cm), and work out the angle inside the function rather than in your head.