The answersDownload the PDF
Worksheet

F3.1 String handling

Strings, lists and records · GCSE · OCR J277 2.2.3, AQA 8525 3.2.8, Edexcel 1CP2 6.3.3 · about 15 min

BugBotLab
NameClassDate

What this lesson is about

Length, indexing, slicing, searching and joining strings, and f-strings.

Questions 11 marks in all

  1. [1 mark]What does this program print?

    first = "Bug"
    second = "Bot"
    print("Hello, " + first + second + ".")
  2. [1 mark]What happens with print("battery: " + 92)?

    1. ATypeError: text and a number cannot be joined with +
    2. BIt prints battery: 92
    3. CIt prints battery: + 92
    4. DSyntaxError
  3. [1 mark]What does this program print?

    speed = 45
    print(f"driving at {speed} and half is {speed / 2}")
  4. [1 mark]What does this program print?

    word = "BugBot"
    print(len(word))
    print(word.upper())
  5. [1 mark]What does this program print?

    print("-" * 5)
  6. [1 mark]What does this program print?

    print(f"{10 / 3:.2f}")
  7. [1 mark]What does this program print?

    word = "BugBot"
    print(word[0], word[3], word[-1])
  8. [1 mark]What does this program print?

    word = "BugBot"
    print(word[1:4])
  9. [1 mark]What does this program print?

    message = "wall ahead"
    print(message.find("ahead"), message.find("ball"))
  10. [1 mark]OCR's name.substring(3, 3) on "BugBot" gives "Bot". What does the second 3 mean?

    1. ATake 3 characters
    2. BStop at index 3
    3. CStart at index 3
    4. DRepeat 3 times
  11. [1 mark]What is joining two strings together called?

    1. AConcatenation
    2. BSlicing
    3. CCasting
    4. DIteration

The task: status report

Drive 10 cm, then print one line in exactly this shape (your numbers will differ):

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

forward(50, distance=10)
x, y = position()
print(f"BugBot at x={x} ...")

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f3-1-string-handling/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Print a name backwards. (Hint: a slice can have a third number, the step, and -1 walks backwards.)
  2. Ask for a sentence and print how many times the letter e appears in it, using count.
  3. Print a report with the heading rounded to a whole number, framed by lines of =.