Functions and structured code · GCSE · OCR J277 2.2.3, AQA 8525 3.2.10, Edexcel 1CP2 6.6.1 · about 15 min
import, Python's own libraries, and a module file of your own.
[1 mark]What does this program print?
import math print(math.sqrt(49))
[1 mark]What does this program print?
from math import floor, ceil print(floor(2.7), ceil(2.1))
[1 mark]Which are benefits of using a library?
Tick every answer that is true.
[1 mark]A program says import moves and calls moves.square(20). Where is square defined?
[1 mark]Why does moves.py need its own from bugbot import * line?
Finish square(size) in moves.py above so it drives a square and ends where it started (replace pass). Then, in the task, import moves and use it to drive a square of 20 cm and then a square of 35 cm. Do not write the square's drives in the task program itself.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() import moves moves.square(20)
Plan your program here, then type it in and press Run.
triangle(size) to moves.py and use it from a Try-it cell.sounds.py on paper: list the functions a robot program would want from it, with their parameters.math.hypot to print how far the robot is from where it started after a zigzag.