Empty

Report a typo

Remember that when using deque, we should control the length of the stack, otherwise an error will arise when it's empty. Let's practice this!

A stack in this task represents a bag with candies. In the beginning, you are given a variable candy_bag. You don't know how many candies there are, but you can be asked to PUT or TAKE one candy at a time. Given a sequence of such actions, print out all candies that are taken from the bag. If there are no more candies, print "We are out of candies :(".

The input will be as follows: first, there's the number n that shows the total number of actions. PUT candy_name denotes putting the corresponding candy into the bag, and TAKE means that we take a candy from the top of the stack.

If the initial stack contains only one candy, Daim, here's an example of what the input might look like:

7
TAKE
PUT Twix
TAKE
TAKE
TAKE
PUT Reesee's
TAKE

And the corresponding output:

Daim
Twix
We are out of candies :(
We are out of candies :(
Reesee's
Write a program in Python 3
from collections import deque

# please don't change the following line
candy_bag = deque(input().split())

# your code here
___

Create a free account to access the full topic