Programming basics · GCSE · OCR J277 2.2.2, AQA 8525 3.2.1, Edexcel 1CP2 6.3.1 · about 15 min
Integer, real, Boolean, character and string, and converting between them.
[1 mark]Which data type best suits whether the robot has bumped into something?
[1 mark]Which data type best suits a distance measured to a tenth of a centimetre, such as 41.3?
[1 mark]What does this program print?
print(int("20") * 3)
print("20" * 3)[1 mark]What does this program print?
print(int(7.9))
[1 mark]What happens with int("twenty")?
[1 mark]What is casting?
[1 mark]Which function turns "2.5" into the number 2.5?
Ask How far? , turn the answer into a number, and drive exactly that far forward. The task will answer 35, so the robot should stop 35 cm up the mat. Your program must work for any distance: do not type 35 into it.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
far = input("How far? ")
forward(50, distance=far)Plan your program here, then type it in and press Run.
type(position()). It is none of the five types above. Find out what it is.