AP CSP Topic 3.10 Coding Practice - Lists

Big Idea 3: Algorithms and Programming · Topic 3.10 · Coding Practice

Lists — 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 Step Log and Traverse and Search, using the same list steps = [8000, 12000, 9000, 15000, 11000]. Now type and run them for real — the problems get harder as you go, ending with a linear search you build from scratch. Remember: the AP pseudocode is 1-indexed, but Python and JavaScript count from 0, so translate carefully. Predict the output first, then check yourself.

Problem 1 of 4

The list steps holds a week of daily step counts. Print the first day's step count on one line, then the number of days logged on the next line. Expected output is 8000 then 5.

Expected output: 8000 5

Show AP pseudocode reference
steps ← [8000, 12000, 9000, 15000, 11000]
DISPLAY(steps[1])
DISPLAY(LENGTH(steps))
On the AP reference sheet the first element is steps[1], but in Python and JavaScript the first element is steps[0]. Use len(steps) in Python (steps.length in JavaScript) for the number of days.

Problem 2 of 4

Traverse the whole list and print the total of all the step counts. Use a loop that adds each element into a running total. Expected output is 55000.

Expected output: 55000

Show AP pseudocode reference
total ← 0
FOR EACH day IN steps
{
  total ← total + day
}
DISPLAY(total)
Start total at 0, then for each value in the list add it to total. In a FOR EACH loop the loop variable is the element's VALUE, not its index, so you add day directly.

Problem 3 of 4

Find and print the best (highest) single-day step count in the list. Seed a 'best so far' with the first element, then keep the larger value as you traverse. Expected output is 15000.

Expected output: 15000

Show AP pseudocode reference
best ← steps[1]
FOR EACH day IN steps
{
  IF(day > best)
  {
    best ← day
  }
}
DISPLAY(best)
Seed best with the first element (steps[0] in Python/JavaScript, steps[1] on the reference sheet). Then compare every element to best and replace best whenever you find a larger value.

Problem 4 of 4

Write a linear search from scratch: scan the list in order and print the 1-indexed day number of the first day that reached the goal of 10000 steps. Stop as soon as you find it. Expected output is 2.

Expected output: 2

Show AP pseudocode reference
goal ← 10000
i ← 1
REPEAT UNTIL(steps[i] ≥ goal)
{
  i ← i + 1
}
DISPLAY(i)
This is a linear search: check each element in order until one meets the goal, then stop. Because Python/JavaScript are 0-indexed, when you find the match at index i, its 1-indexed day number is i + 1. Day 1 is 8000 (below goal); day 2 is 12000 (first to reach 10000).

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.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]