...

Chapter 9 - Python Quest

Stacks

Push, pop, undo, browser history, matching pairs, and tiny calculators.

XP
0Level 1
Stars
0/15quest stars
Combo
0clean runs
Rank
Seed0/160 Python score
Stacks

Snack Stack Top

100 XP

The snack helper stacks treats on a tray. New snacks go on top, and TAKE removes the snack from the top of the tray.

Write snack_stack_top(moves) so it follows each move and returns the snack on top at the end, or empty if the stack has no snacks.

Sample checks

snack_stack_top(["apple","cookie","TAKE","juice"])returns"juice"

Explanation: apple goes down, cookie goes on top, TAKE removes cookie, then juice becomes the top

snack_stack_top(["book","TAKE"])returns"empty"

Explanation: book is added, then TAKE removes it, so nothing is left

Hint

Hints are ready when you want one.

Lesson reference

Review: Push and pop

Your Python

snack_stack_top

Loading editor

Judge

Ready

0/4

Run your code when it feels ready.