String manipulation – OCR GCSE Computer Science lesson (J277)
Pupils learn to use concatenation, length, slicing, upper and lower case and ASCII conversion in Python and OCR Exam Reference Language to build and extract parts of strings.
Lesson 2 of 11 in unit 10.4 Characters, Images, Sound, Strings and Arrays, taught in Year 10, Spring 2. It answers one big question: How can a program take apart and join up text?
By the end, pupils can use concatenation, length, slicing, upper and lower case and ASCII conversion in Python and OCR Exam Reference Language to build and extract parts of strings.
- The Build (the main task)
- Write a program that inputs a fan's first name, surname and birth year, then uses slicing and concatenation to print their wristband code: the first three letters of the surname in upper case, then the last two digits of the year, then the number of letters in the first name. For example, Ruby Okafor 2010 gets OKA104.
- Support version
- Parsons problem: the program's lines are jumbled, with one distractor line that slices surname[1:4] and misses the first letter.
- Challenge
- Use ord() and chr() to add a check letter to the end of the code: the letter after the code's first letter.
- Real-world link
- Each fan's wristband has a code made from their name and birth year.
- Key words
- Concatenation, Slicing and Extract, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “A slice includes its end position, so word[0:3] gives four characters”; “The first character of a string is at position 1”.
- OCR J277 specification
- 2.2.3 (additional programming techniques: string manipulation (length, case, substrings, concatenation, ASCII conversion) and 1D and 2D arrays).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Pupils need computers for the main task.
Also sold in the Characters, Images, Sound, Strings and Arrays unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
More for GCSE Computer Science (OCR)
See allPupils learn to explain how a character set gives each character a binary code, encode and decode text with ASCII, and compare ASCII and Unicode by bits per character and range.
Free sample lessonPupils learn to explain how a bitmap image is stored as pixels with binary colour codes, and describe how colour depth and resolution affect quality and file size.
How big will an image file be before we save it? One complete OCR GCSE Computer Science (J277) lesson with slides, worksheets and a lesson plan.
Written for the specifications named. Not endorsed by or affiliated with any exam board.