0% found this document useful (0 votes)
74 views4 pages

Xii Stack

The document outlines various programming tasks related to stack operations using Python. It includes the creation of user-defined functions for pushing and popping elements from stacks based on specific criteria, such as student marks, book prices, and customer names. Each task provides examples and expected outputs for clarity.
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)
74 views4 pages

Xii Stack

The document outlines various programming tasks related to stack operations using Python. It includes the creation of user-defined functions for pushing and popping elements from stacks based on specific criteria, such as student marks, book prices, and customer names. Each task provides examples and expected outputs for clarity.
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
You are on page 1/ 4

BHARATHI VIDHYALAYA SENIOR SECONDARY SCHOOL

WORK SHEET – STACK


CLASS: XII SUBJECT: COMPUTER SCIENCE
1. A dictionary stu contains rollno and marks of students. Two empty list stack_roll and stack_mark will
be used as stack. Two function push_stu() and pop_stu() is defined and perfom following operation
(a) Push_stu() :- It reads dictionary stu and add keys into stack_roll and values into stack_marks for all
students who secured more than 60 marks.
(b) Pop_stu() :- it removes last rollno and marks from both list and print “underflow” if there is nothing
to remove

For example
stu={1:56,2:45,3:78,4:65,5:35,6:90}
values of stack_roll and stack_mark after push_stu()
[3,4,6] and {78,65,90}
2. A List contains following record of a Book :
[Book Name, Write Name, Price]
Write the following user defined functions to perform given operations on the stack named “BOOK” :
(i) Push_Rec( ) – To push the record containing Book name and author name of Books having price >
500 to the stack.
(ii) Pop_Rec( ) – To pop the objects from the stack and display them. Also display “STACK
UNDERFLOW” when there are no elements in the Stack.
3. A list contains following record of a student:
[student_name, marks, subject]
Write the following user defined functions to perform given operations on the stack named ‘status’:
(i) Push_element() - To Push an object containing name and marks of a student who scored more than
75 marks in ‘CS’ to the stack
(ii) Pop_element() - To Pop the objects from the stack and display them. Also, display “Stack Empty”
when there are no elements in the stack.
For example:
If the lists of customer details are:
[“Danish”,80,”Maths”]
[“Hazik”,79,”CS”]
[“Parnik”,95,”Bio”]
[“Danish”,70,”CS”]
[“Sidhi”,99,”CS”]
The stack should contain
[“Hazik”,”79”]
[“Sidhi”,”99”]
The output should be:
[“Hazik”,”79”]
[“Sidhi”,”99”]
Stack Empty
4. A list contains following record of a student: [Rno, Name, Dob, Class]
Write the following user defined functions to perform given operations
on the stack named ‘status’:
(i) Push_element() - To Push an record of student to the stack
(ii) Pop_element() - To Pop the objects from the stack and display them. Also, display “Stack Empty”
when there are no elements in the stack.
5. Alam has a list containing 10 integers. You need to help him create a program with separate user
defined functions to perform the given operations based on this list.
(a) Traverse the content of the list and push the even numbers into a stack.
(b) Pop and display the content of the stack.
For example, If the sample content of the list is as follows
N = [12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
38 2 98 56 34 12
6. Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a
program, with separate user defined functions to perform the following operations.
(a) Push the keys (name of the student) of the dictionary into a stack, where the corresponding value
(marks) is greater than 75.
(b) Pop and display the content of the stack. For example If the sample content of the dictionary is as
follows
R={“OM”:76, “JAI”:45, “BOB”:89, “ALI”:65, “ANU”:90, “TOM”:82}
The output from the program should be
TOM ANU BOB OM
7. Two list Lname and Lage contains name of person and age of person respectively. A list named
Lnameage is empty. Write functions as details given below
(i) Push_na() :- it will push the tuple containing pair of name and age from Lname and Lage whose age
is above 50
(ii) Pop_na() :- it will remove the last pair of name and age and also print name and age of removed
person. It should also print “underflow” if there is nothing to remove

For example the two lists has following data


Lname=[‘narender’, ‘jaya’, ‘raju’, ‘ramesh’, ‘amit’, ‘Piyush’]
Lage=[45,23,59,34,51,43]
After Push_na() the contains of Lnameage stack is
[(‘raju’,59),(‘amit’,51)]
The output of first execution of pop_na() is
The name removed is amit
8. Write a function AddCustomer(Name) in Python to add a new Customer information NAME into the
List of CStack and display the information.
9. Write a function DeleteCustomer() to delete a Customer information from a list of CStack. The
function delete the name of customer from the stack
10. Write a function DeleteCustomer() to delete a Customer information from a list of CStack. The
function delete the name of customer from the stack.
Example: If the stack contains [“Abhinav”,”Vimank”],
the output should be:
Vimank
Abhinav
11. Write a function in Python POP(cities), where cities is a stack implemented by a list of city names for
eg. cities=[‘Delhi’, ’Jaipur’, ‘Mumbai’, ‘Nagpur’]. The function returns the value deleted from the
stack.
12. Write a function in python Popstack(Lst), where Lst is a stack implemented by a list of numbers. The
function returns the value deleted from the stack.
13. Write a function in Python PUSH(A), where A is a list of numbers. From this list push all even
numbers into a stack implemented by using a list. Display the stack if it has at least one element,
otherwise display appropriate error message.
14. Write a function in Python 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 error message.
15. Write a function in Python PUSH(Num), where Num is a list of integer numbers. From this list push all
positive even numbers into a stack implemented by using a list. Display the stack if it has at least one
element, otherwise display appropriate error message.
16. Write a function in Python PUSH_VAL(val), where val is a list of numbers. From this list push all odd
numbers into a stack implemented by using a list. Display the stack if it has at least one element,
otherwise display appropriate messages.
17. Write a function in Python PushBook(Book) to add a new book entry as book_no and book_title in the
list of Books , considering it to act as push operations of the Stack data structure.
18. Write a function in Python, Push(book) where, book is a dictionary containing the details of a book in
form of {bookno : price}.
The function should push the book in the stack which have price greater than 300. Also display the
count of elements pushed into the stack.
For example:
If the dictionary contains the following data:
Dbook={"Python":350,"Hindi":200,"English":270,"Physics":600, “Chemistry”:550}
The stack should contain
Chemistry
Physics
Python
The output should be:
The count of elements in the stack is 3
19. Write a function in Python, Push(emp) where , emp is a dictionary containing the details of employees
– {empname:salary}.
The function should push the names of those employees in the stack who have salary less than 15000.
Also display the count of elements pushed into the stack.
For example:
If the dictionary contains the following data:
Employee ={"Sohan”:20000,”Mohan”:9000,”Rohan”:25000,”Aman”:5000}
The stack should contain
Mohan
Aman
The output should be:
The count of elements in the stack is 2
20. Write a function in Python, Push(Item) where Item is a list containing the details of Bakery Items –
[[Name, Price], [Name, Price], [Name, Price]]
The function should push the names of those items in the Stack who have price less than Rs. 50. Also
display the count of elements pushed into the Stack.
Example:
If the list contains the following items :
l=[['ravi',26],['raman',36], ['chaman',56]]
The Stack should contain :
Ravi
Raman
The output should be :
The number of elements in stack is : 2
21. Write a function in python, PushEl(e) to add a new element and PopEl(e) to delete a element from a
List , considering them to act as push and pop operations of the Stack data structure .
22. Write a function in python, PushEl(element) and MakeEl(element) to add a new element and delete a
element from a List of element Description, considering them to act as push and pop operations of the
Stack data structure .
23. Write a function in python, pushme (stock, item) and popme(stock ) to add a new item and delete an
item from the stock, considering them to act as push and pop operations of the stack.
24. Write a function POP(Book) in Python to delete a Book from a list of Book titles, considering it to act
as a pop operation of the Stack data structure.
25. Write Push (contents) and Pop (contents) methods in Python to add numbers and remove numbers
considering them to act as Push and Pop operations of stack.
26. Write PUSH_CITY(cities) and POP_CITY(cities) methods/functions in Python to add new city name
and delete city name from a List of cities, considering them to act as push and pop operations of the
Stack data structure.
27. Write PushOn(Book) and Pop(Book) methods/functions in Python to add a new Book and delete a
Book from a List of Book titles, considering them to act as push and pop operations of the Stack data
structure.
28. Write PushOn(Student) and Pop(Student) methods/functions in Python to add a new Student and delete
a Student from a list of Student Name, considering them to act as push and pop operations of the Stack
data structure.
29. Write the definition of a user defined function Push3_5(N) which accepts a list of integers in a
parameter N and pushes all those integers which are divisible by 3 or divisible by 5 from the list N into
a list named Only3_5.
Write a program in Python to input 5 integers into a list named NUM.
The program should then use the function Push 3_5() to create the stack of the list Only3_5. Thereafter
pop each integer from the list Only3 5 and display the popped value. When the list is empty, display
the message "StackEmpty".
For example:
If the integers input into the list NUM are:
[10, 6, 14, 18, 301
Then the stack Only3 5 should store
[10, 6, 18, 301
And the output should be displayed as
30 18 6 10 StackEmpty
30. Write the definition of a user defined function PushNV(N) which accepts a list of strings in the
parameters N and pushes all strings which have no vowels present in it, into a list named NoVowel.
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() to create a stack of words in the list NoVowel so
that it stores only those words which do not have any vowels in it, from the list All.
Thereafter , pop each word from the list NoVowel and display the message “EmptyStack”
For example:
If the words accepted and pushed into the list All are
[‘DRY’,’LIKE’,’RHYTHM’,’WORK’,’GYM’]
Then the stack NoVowel should store
[‘DRY’,’RHYTHM’,’GYM’]
And the output should be displayed as
GYM RHYTHM DRY EmptyStack
31. Write the Push operation of stack containing person names. Notice that the name should only accept
characters, spaces and period (.) except digits. Assume that Pname is a class instance attribute.

You might also like