0
0
DSA Pythonprogramming~10 mins

Why Stack Exists and What Problems It Solves in DSA Python - Test Your Knowledge

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to push an element onto the stack.

DSA Python
stack = []
stack.[1](5)
print(stack)
Drag options to blanks, or click blank then click option'
Ainsert
Bappend
Cremove
Dpop
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of append
Using remove which deletes a value
2fill in blank
medium

Complete the code to remove the top element from the stack.

DSA Python
stack = [1, 2, 3]
top = stack.[1]()
print(top)
print(stack)
Drag options to blanks, or click blank then click option'
Aappend
Binsert
Cremove
Dpop
Attempts:
3 left
💡 Hint
Common Mistakes
Using append instead of pop
Using remove which deletes by value
3fill in blank
hard

Fix the error in the code to check if the stack is empty.

DSA Python
stack = []
if len(stack) [1] 0:
    print('Stack is empty')
else:
    print('Stack is not empty')
Drag options to blanks, or click blank then click option'
A==
B!=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which checks for not empty
Using > or < which are incorrect here
4fill in blank
hard

Fill both blanks to create a stack and push an element.

DSA Python
stack = [1]
stack.[2](10)
print(stack)
Drag options to blanks, or click blank then click option'
A[]
Bappend
Cpop
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using {} which creates a dictionary
Using pop to add elements
5fill in blank
hard

Fill all three blanks to pop an element and check if stack is empty.

DSA Python
stack = [5, 6, 7]
top = stack.[1]()
if len(stack) [2] 0:
    print('Stack is empty after popping')
else:
    print('Stack still has elements')
print('Popped element:', [3])
Drag options to blanks, or click blank then click option'
Aappend
Bpop
C==
Dtop
Attempts:
3 left
💡 Hint
Common Mistakes
Using append instead of pop
Using != instead of ==
Printing stack instead of popped element