0
0
DSA Pythonprogramming~10 mins

Check if Stack is Empty or Full in DSA Python - Interactive Practice

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

Complete the code to check if the stack is empty.

DSA Python
def is_empty(stack):
    return len(stack) == [1]
Drag options to blanks, or click blank then click option'
A0
B1
C-1
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 to check empty stack.
2fill in blank
medium

Complete the code to check if the stack is full given max size.

DSA Python
def is_full(stack, max_size):
    return len(stack) == [1]
Drag options to blanks, or click blank then click option'
Amax_size - 1
Bmax_size
Clen(stack)
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using max_size - 1 instead of max_size.
3fill in blank
hard

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

DSA Python
def is_empty(stack):
    if stack == [1]:
        return True
    else:
        return False
Drag options to blanks, or click blank then click option'
AFalse
BNone
C0
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing stack to None instead of [].
4fill in blank
hard

Fill both blanks to check if stack is full given max size.

DSA Python
def is_full(stack, max_size):
    if len(stack) [1] max_size:
        return True
    else:
        return [2]
Drag options to blanks, or click blank then click option'
A==
BFalse
C!=
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' in condition.
Returning True when stack is not full.
5fill in blank
hard

Fill all three blanks to check if stack is empty or full.

DSA Python
def check_stack(stack, max_size):
    if len(stack) [1] 0:
        return '[2]'
    elif len(stack) [3] max_size:
        return 'Full'
    else:
        return 'Not full or empty'
Drag options to blanks, or click blank then click option'
A==
BEmpty
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' to check empty or full.