The answersDownload the PDF
Worksheet

F1.8 Data types and casting

Programming basics · GCSE · OCR J277 2.2.2, AQA 8525 3.2.1, Edexcel 1CP2 6.3.1 · about 15 min

BugBotLab
NameClassDate

What this lesson is about

Integer, real, Boolean, character and string, and converting between them.

Questions 7 marks in all

  1. [1 mark]Which data type best suits whether the robot has bumped into something?

    1. ABoolean
    2. BInteger
    3. CString
    4. DReal
  2. [1 mark]Which data type best suits a distance measured to a tenth of a centimetre, such as 41.3?

    1. AReal
    2. BInteger
    3. CBoolean
    4. DCharacter
  3. [1 mark]What does this program print?

    print(int("20") * 3)
    print("20" * 3)
  4. [1 mark]What does this program print?

    print(int(7.9))
  5. [1 mark]What happens with int("twenty")?

    1. AA ValueError: there is no number in the text
    2. BIt gives 20
    3. CIt gives 0
    4. DIt gives the string "twenty"
  6. [1 mark]What is casting?

    1. AConverting a value from one data type to another
    2. BStoring a value in a variable
    3. CPrinting a value
    4. DRounding a number
  7. [1 mark]Which function turns "2.5" into the number 2.5?

The task: drive what you type

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.

QR code
Do it on the robot
www.bugbotlab.com/learn/f1-8-data-types-and-casting/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Ask for a number of seconds and wait that long, with the LED on.
  2. Ask for a distance in metres and drive that many metres, converting to centimetres.
  3. Print type(position()). It is none of the five types above. Find out what it is.