AP CSP Topic 3.2 Coding Practice - Data Abstraction
Big Idea 3: Algorithms and Programming · Topic 3.2 · Coding Practice
Data Abstraction — Code It Yourself
Write real code and check it against the expected output. Pick Python or JavaScript; the AP pseudocode reference is there when you need it.
You warmed these up on paper in Trace the List and One Name for Many. Now build and run them for real with the weather station's daily-high temperatures — the problems get harder as you go, ending with one you build from scratch. Remember: the exam sheet counts from index 1, but Python counts from index 0, so translate every position down by one when you code. Predict the output first, then check yourself.
Problem 1 of 4
Create a list named temps holding the daily highs 68, 72, 75, 70, then print exactly the FIRST reading: 68
Expected output: 68
Show AP pseudocode reference
temps ← [68, 72, 75, 70]
DISPLAY(temps[1])
Build the list with square brackets and commas. The exam sheet's first element is temps[1]; in Python and JavaScript that same first element is temps[0].
Problem 2 of 4
Start with temps holding 68, 72, 75, 70. Append a new reading, 81, to the end, then print how many readings are now stored.
Expected output: 5
Show AP pseudocode reference
temps ← [68, 72, 75, 70]
APPEND(temps, 81)
DISPLAY(LENGTH(temps))
Appending adds one element to the end, so the length grows by 1. Use the length function/property to count the elements after appending — do not hard-code 5.
Problem 3 of 4
The list temps holds 68, 72, 75, 70. Print the THIRD reading and the LAST reading on one line, separated by a space, like: 75 70
Expected output: 75 70
Show AP pseudocode reference
temps ← [68, 72, 75, 70]
DISPLAY(temps[3])
DISPLAY(temps[4])
The exam sheet's third element temps[3] is Python's temps[2]. The last element is at index len(temps)-1, which reaches the end no matter how long the list is.
Problem 4 of 4
Build the abstraction from scratch: create a list named highs holding 90, 85, 88, append 92, then print the FIRST and LAST readings separated by a space, like: 90 92
After appending, the last element is at index len(highs)-1 (exam sheet index LENGTH(highs)). The first element is highs[0] in Python (exam sheet highs[1]). Join the two with a space.
Your code runs on a secure external service. Answers are checked automatically — nothing is stored.
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed.
Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Typically responds within 24 hours
✓
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.