CBSE 2026 · Central · Set 4 · Q30 · 3 marks
A stack named FruitStack, implemented using list, contains records of some fruits. Each record is represented as a dictionary with keys 'Name', 'Origin', 'Price', and 'Expiry'. A sample record is given here :{'Name':'Apple','Origin':'France','Price':120,
'Expiry':'12-08-2025'}
Write the following user-defined functions in Python to perform the specified operations on FruitStack :(i)push_fruit(FruitStack, Fruit) : This function takes the stack FruitStack and a new record Fruit as arguments and pushes the record stored in Fruit onto FruitStack if the Price is less than 100.(ii)pop_fruit(FruitStack): This function pops the topmost record from the stack and returns it. If the stack is already empty, the function should display "UNDERFLOW".(iii)display(FruitStack): This function displays all the elements of the stack starting from the topmost element. If the stack is empty, the function should display 'EMPTY STACK'.Write a Python program to accept $\displaystyle 10$ integers from the user. If the entered number is a three-digit even integer, push it onto a stack. After all inputs are taken, pop all the three-digit even integers from the stack and display them. For example, if the user enters $\displaystyle 12$, $\displaystyle 31$, $\displaystyle 320$, $\displaystyle 457$, $\displaystyle 6$, $\displaystyle 92$, $\displaystyle 924$, $\displaystyle 220$, $\displaystyle 1$, $\displaystyle 218$, then the stack should contain : \[\text { 320, 924, 220, } 218 \] and the output of the program should be : \[218220924320 \]
A stack named FruitStack, implemented using list, contains records of some fruits. Each record is represented as a dictionary with keys 'Name', 'Origin', 'Price', and 'Expiry'. A sample record is given here :
{'Name':'Apple','Origin':'France','Price':120,
'Expiry':'12-08-2025'}Write the following user-defined functions in Python to perform the specified operations on FruitStack :
(i)
push_fruit(FruitStack, Fruit) : This function takes the stack FruitStack and a new record Fruit as arguments and pushes the record stored in Fruit onto FruitStack if the Price is less than 100.
(ii)
pop_fruit(FruitStack): This function pops the topmost record from the stack and returns it. If the stack is already empty, the function should display "UNDERFLOW".
(iii)
display(FruitStack): This function displays all the elements of the stack starting from the topmost element. If the stack is empty, the function should display 'EMPTY STACK'.
Write a Python program to accept $\displaystyle 10$ integers from the user. If the entered number is a three-digit even integer, push it onto a stack. After all inputs are taken, pop all the three-digit even integers from the stack and display them. For example, if the user enters $\displaystyle 12$, $\displaystyle 31$, $\displaystyle 320$, $\displaystyle 457$, $\displaystyle 6$, $\displaystyle 92$, $\displaystyle 924$, $\displaystyle 220$, $\displaystyle 1$, $\displaystyle 218$, then the stack should contain : \[\text { 320, 924, 220, } 218 \] and the output of the program should be : \[218220924320 \]
Marking-scheme solution
(i) def push_fruit(FruitStack, Fruit):
if Fruit['Price']<100:
FruitStack.append(Fruit)
def push_fruit(FruitStack, Fruit): #Option 2(i)
if Fruit['Price']<100:
FruitStack.insert(0,Fruit)Data Structure - StackImplementation of Stack using ListApplyshort_answer
CBSE Class 12 Computer Science past-paper question from the 2026board exam, with the answer as CBSE’s own marking scheme gives it. Where our answers come from.