thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

03.02 · Find and sort items / Practice · 8 min

Find a movie, purple and a missing teal

The movie and purple have positions. Missing teal needs a clear fallback, not a crash.

Activity 2 of 4 in Find and sort items

All courses

Python 3: Lists / 03.02

Finding items challenge

Not started

Complete the three original search challenges with present and absent color paths.

More options

Your lesson progress

Walkthrough: not startedPractice: not started

Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

Rob searches a movie list for Pixel, finds purple at index 4 and reports missing teal safely.
Rob’s comic strip · Find and sort items

ORIGINAL WALKTHROUGH · 08:05

Watch with Rob.

Pause whenever you want to try a change. You can return to the lesson at any time.

LEARN WITH THE CODE ZONE

Unlock this video walkthrough

Written lessons and coding practice are free. Video walkthroughs are included with a paid Code Zone membership or an active free trial.

Have a Code Zone website account? Use your learning account’s email to get a six-digit sign-in code, or use your existing website password.

Need a website account? Paid Skool members and active trial members can use the email from their membership questions to request a sign-in code. No invite link or Skool password needed.

Close this window to keep practicing. After signing in, you’ll return to this lesson.

Video walkthroughs are included with an active Code Zone membership. The written lesson and practice are free.

Open video & code editor (opens in a new tab)

Starter source code for VS Code

Copy the source below or download the file to follow along in VS Code.

The download includes a lesson link in each file and a README so you can find your way back.

main.py
main.pypython · example
# Code along with Rob: Finding items challenge
# Find a movie in five titles.
# Check purple in six colors before finding its index.
# Use try/except ValueError when searching for missing teal.
# Predict each result, then press play.

Your task: three searches

Keep the five supplied movie titles. Assign the position of "Pixel" to movie_position using index, then print movie_position.

Keep the six supplied colors. Use an if membership check for "purple". Assign its numeric position to purple_position and its printable text to purple_message. If missing, use -1 as your own marker and "purple not found" as the message. Print purple_message.

Use try and except ValueError when searching for "teal". Store the found position as text in teal_message, or "teal not found" if missing. Print teal_message. The checks expect 3, 4 and teal not found on separate lines for the supplied inputs.

A marker you choose is not what index returns

Our -1 marker only belongs to the missing-purple branch you write. index itself still raises ValueError if called with a missing value. The supplied data includes purple and excludes teal, so both techniques have a clear role.

Checks compare output and named results for these fixed inputs. They do not prove that your source uses the requested if and try statements. After passing, replace purple with pink, then add teal in another experiment. Predict each branch; restore the original inputs before checking again.

Review the source after trying it

The original 8:05 walkthrough and Solution Set remain in Skool. Use its separate code-along workspace if you want to follow the recording without replacing this challenge draft.

Build it one step at a time

Prefer learning by typing? Work through short instructions, run the Python code and check each change before continuing. Your guided project saves separately from the challenge below.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

4 steps · Saved work · Instant feedback

YOUR TURN

Handle each search outcome

Find Pixel; guard purple with membership; handle missing teal with except ValueError. Preserve both input lists and print the three requested results.

Expected output
3
4
teal not found

Keep the starting inputs. Print these lines in this order, without extra output.

  • Keep the requested movie position
  • Keep the requested purple position
  • Keep the requested purple message
  • Keep the requested teal message
  • Keep the requested movies
  • Keep the requested colors
  • Output 1 matches the requested result
  • Output 2 matches the requested result
  • Output 3 matches the requested result

Edit Python, then run it. Check challenge checks your output and the listed Python requirements. Your code saves on this browser after a short pause. Sign in and choose Save account draft to keep it across devices. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Need a nudge?

Search the list by value

movies.index("Pixel") returns a number. Keep the actual movie list and search value rather than hardcoding that number.

Give missing colors a deliberate path

Check "purple" in colors before index. Catch ValueError around the teal index call. Convert a found numeric position with str when storing the message.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Found-at-zero, found-later and not-found are distinct outcomes. Test all three when searching a collection.