0% found this document useful (0 votes)
9 views3 pages

Stack Assignment 2026

The document provides a revision sheet for Computer Science students at Archies Higher Secondary School, focusing on user-defined functions in Python for stack operations. It includes tasks such as pushing and popping color records, customer names, and numbers based on specific criteria, as well as handling lists and dictionaries. Additionally, it covers stack operations, including checking for underflow and displaying stack contents.

Uploaded by

demonrajaji
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Stack Assignment 2026

The document provides a revision sheet for Computer Science students at Archies Higher Secondary School, focusing on user-defined functions in Python for stack operations. It includes tasks such as pushing and popping color records, customer names, and numbers based on specific criteria, as well as handling lists and dictionaries. Additionally, it covers stack operations, including checking for underflow and displaying stack contents.

Uploaded by

demonrajaji
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ARCHIES HIGHER SECONDARY SCHOOL – KANPUR

Subject : Computer Science

Revision Sheet ( Sure short in boards)

1. A stack, named clrstack, contains records of some colours. Each record is represented as
a tuple containing four elements. Color name, RED, GREEN , BLUE . Colour name is string
and RED , GREEN , BLUE are integers For example , a record in the stack may be
(‘yellow’,237,250,68) . Write the following user defined function in Python to perform the
specified operation on clrstack : (2025 boards)

a) push_clr(clrstack, new_clr): This function takes the stack clrstack and a new record new_clr
as argument and pushes this new record onto the stack.

b) pop_clr(clrstack): This function pops the topmost record from the stack and returns it. If
the stack is already empty, the function should display the message “ underflow”

c) isempty(clrstack): this function checks whether the stack is empty or not . If the stack is
empty , the function should returns true , otherwise the function should returns false.

2. Write the following user defined function in Python : (2025)

1. push_trail(N,mystack): Here N and mystack are lists, and mystack represents a stack. The
function should push the last 5 elements from the list N onto the stack mystack. For example
if the list is N and the value is [1,2,3,4,5,6,7] , Then the function push_trail() should push the
elements 3,4,5,6,7 onto the stack. Therefore the value of stack will be [3,4,5,6,7]

Assume N contains at least 5 elements.

2., pop_one(mystack): The function should pop elements from the stack mystack, and return
this element. If the stack is empty, then the function should display the message ‘stack
underflow’ and returns None.

3. Display_all ( mystack): The function should display all the elements of the stack mystack.
Without deleting them. If the stack is empty , the function should display the message “empty
stack “.

3. Consider a list named Nums which contains random integer. (2024 boards)

1. pushbig(): It checks every number from the list nums and pushes all such numbers which
have 5 or more digits into the stack bignums

2. popbig() – it pops the numbers from the stack, bignums and display them. The function
should also display “ stack is empty “ when there are no more numbers left in the stack.

For example if the list contains numbers =[10025,254923,1297653,31498,386,92765]

And the execution popbig() the following output should be displayed.

92765

386
3. A list contains the following record of customer [ customer_name, room_type] (2023)

Write the following user defined functions to perform given operation on the stack named
“ Hotels”.

1. push_cust() – To push customers name of those customers who are staying in ‘ delux “ room
type.

2. Pop_cust() – To pop names of customers from the stack and display them. Also display
‘underflow” when there is no customer in the stack

4. Write a function in Python, push(vechicle) where, vehicle is a dictionary containing details


of vehicle [ car_name : maker]

The function should push the names of car manufactured by ‘ TATA’ including all the possible
cases like TATA, HUNDAI etc.

If the dictionary contains the following data :

Vehicle =[ ‘santro’:’hyundai’,’Nexon’:’TATA’,’Safari’: ‘TATA’]

The stack should contains

Safari

Nexon

4. Write a function definition of a user defined function PushNV(N) which accept a list of
strings in the parameter N and pushes all strings which have no vowels present in it, into
the list named NoVowel. (2022 boards)
* Write a program in Python to input 5 words and push them one by one into a list named all.

The program should then use the function PushNV(N) to create a stack of words in the list
NoVowel so that it stores only those words which do not have any vowel present in it. From
the list all.

Thereafter , pop each word from the list NoVowel and display popwords . When the stack is
empty , display the message “ Empty stack “

For example

If the word accepted and pushed into the list All are

[‘DYE’,’LIKE’,’RHYTHM’,’WORK’,’GYM’]

Then the stack NoVowel should store

[ ‘DYE’,’RHYTHM’,’GYM’]

And the output should be displayed as GYM , RHYTHM , DRY Empty Stack

5. Stack is a linear data structure which follows a particular order in which operations are
performed . What is the order in which the operations are performed in a stack? Name the
method or function available in python which is used to remove the last element from the
list implemented stack. Also write an example using Python statement for removing last
element of the list ( CBSE -2022)

6. Write a function in python makepush(package) and markpop(package) to add new


package and delete package from list of package description Considering them to act as push
and pop operation of the stack data structure ( package contains package id and package
title)

( CBSE Compartment -2020)

7. Julie has created a dictionary containing names and marks as key value pairs of 6 students.
Write a program with separate user defined function to perform the following operations

i) push the keys (name of students)of the dictionary to stack , where the corresponding values
(marks) is 75 or more.

ii) pop and display the content of the stack for example if the dictionary is –

r={“om”:76,”jai”:45,”bob”:89,”ali”:65,”anu”:90,”tom”:82}

The output of the program is tom anu bob om ( CBSE SAMPLE PAPER)

8. Write a function in pythob push(arr) , where arr is a list of numbers. From this list push
all numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at
least one element, otherwise display appropriate message ( CBSE SAMPLE PAPER)

9. Write the user defined function –

1) push_even(N) – This function accepts a list of integers named N as parameter. It then


pushes only even numbers into the stack named even.

2) pop_even(N) – This function pops each integer from the stack even and display the popped
value.

When the stack is empty the message stack empty is displayed. For example if the list n
contains [10,5,3,8,15,4] Then the stack , even should store [10,8,4] and the output should be
4 8 10 stack empty . (CBSE Compartment 2022)

10. Consider a stack as a list containing the following data.

Stack = [100,200,300,400,500,600]
Display the stack after each operations
[Link]()
[Link](700)
[Link]()
[Link](800)
[Link](900)
[Link]()
~~~~~~~~~~~~~~~~~

You might also like