Skip to main content
AP CSP course

F08 · Topic 3.4

Text transformation studio

Use an explicitly documented text interface, track intermediate strings and test boundaries without assuming another language’s substring conventions.

1. Predict first

The supplied slice(text,start,count) uses one-based positions and returns up to count available characters. Predict slice("PLANET",2,3) and its length.

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 1PLANETWaiting
  2. Input 22Waiting
  3. Input 33Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Try count 0, a count beyond the end, and start one past the last character.

2. Build your procedure

Write a label-building algorithm using the supplied slice and concatenation contracts. Give tests for count 0, a slice reaching the end and a slice asking beyond the end.

Use AP CSP pseudocode, a language you know, or precise plain language. Your code is not executed here. Use the classroom assignment to save your response.

3. Check boundaries

Public worked tests for the fixed model
InputExpectedWhy this case
PLANET,start 2,count 3LAN; length3Position and count differ from an end index.
PLANET,start 6,count 4T; length1Only available characters are returned.
PLANET,start 1,count 0Empty string; length 0Zero count is allowed.

4. Explain and reflect

Why is it unsafe to use the behaviour of a Python or Java substring function without checking this supplied contract?

Model limits: The fixed tool uses ASCII text only, one-based start and a count, including documented truncation at the end. It is not the AP reference sheet defining a universal SLICE primitive.

Teacher guidance and scoring