Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA Python
stack = [] element = 5 stack.[1](element) print(stack)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of append removes an element instead of adding.
Using remove tries to delete a specific value, not add one.
✗ Incorrect
The append method adds an element to the end of the list, which is the top of the stack.
2fill in blank
mediumComplete the code to push multiple elements onto the stack using a loop.
DSA Python
stack = [] for i in range(3): stack.[1](i) print(stack)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop removes elements instead of adding.
Using extend expects an iterable, not a single element.
✗ Incorrect
Inside the loop, append adds each number to the stack one by one.
3fill in blank
hardFix the error in the push operation code.
DSA Python
stack = [] element = 10 stack.[1](element) print(stack)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using push causes an AttributeError because lists don't have this method.
Using add is for sets, not lists.
✗ Incorrect
Python lists do not have a push method; use append to add elements.
4fill in blank
hardFill both blanks to create a stack and push an element onto it.
DSA Python
stack = [1] element = 7 stack.[2](element) print(stack)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using {} creates an empty dictionary, not a list.
Using pop removes elements instead of adding.
✗ Incorrect
Use [] to create an empty list as a stack and append to push an element.
5fill in blank
hardFill all three blanks to push elements 1, 2, and 3 onto the stack.
DSA Python
stack = [1] stack.[2](1) stack.[3](2) stack.append(3) print(stack)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using {} creates a dictionary, not a stack.
Using pop removes elements instead of adding.
✗ Incorrect
Create an empty list with [] and use append to push each element.