F08 · Topic 3.4
Text transformation studio
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
- Input 1PLANETWaiting
- Input 22Waiting
- 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
| Input | Expected | Why this case |
|---|---|---|
| PLANET,start 2,count 3 | LAN; length3 | Position and count differ from an end index. |
| PLANET,start 6,count 4 | T; length1 | Only available characters are returned. |
| PLANET,start 1,count 0 | Empty string; length 0 | Zero 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.