Loading...
Loading...
Loading...
A support tool keeps a stack of ticket numbers. Commands arrive one per line. push x adds ticket x on top. pop removes the top ticket and prints it. top prints the top ticket without removing it. If the stack is empty, pop and top print EMPTY.
push x, pop or top.Example 1
Input
5 push 10 push 20 top pop pop
Output
20 20 10
Prints 20, 20 and 10.
Example 2
Input
2 pop top
Output
EMPTY EMPTY
Try the problem first. Open one hint at a time.
A Python list is the stack: append, pop and [-1].
Test if stack: before reading the top.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor