Programming basics · GCSE · about 25 min
Plan, build and test one program that asks, drives a square, plays notes and reports.
[1 mark]In the project, which of these is an output?
[1 mark]What does this program print?
side = float("12.5")
print("perimeter:", 4 * side)
print("area:", side * side)perimeter: 50.0 area: 156.25
side is 12.5, so the perimeter is 50.0 and the area is 156.25.
[1 mark]Why does the project convert the note with int but the side with float?
[1 mark]You test with a side of 10. What should the area be?
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() SPEED = 50 # ask the two questions and convert the answers # drive the square, a note at each corner # print the perimeter and the area
The hint students can ask for: Ask for both answers and convert each to the kind of number it should be: a side can have a decimal, a note cannot. Drive the four sides in order, sounding the note after each one, then work the perimeter and area out from the side you were given.
from bugbot import *
connect()
SPEED = 50
# ask the two questions and convert the answers
side = float(input("How long is each side, in cm? "))
note = int(input("Which note, in hertz? "))
# drive the square, a note at each corner
forward(SPEED, distance=side)
tone(note, 0.2)
right(SPEED, distance=side)
tone(note, 0.2)
backward(SPEED, distance=side)
tone(note, 0.2)
left(SPEED, distance=side)
tone(note, 0.2)
# print the perimeter and the area
print("perimeter:", 4 * side)
print("area:", side * side)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.