0% found this document useful (0 votes)
134 views11 pages

Data Structures Worksheet

Uploaded by

SR
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)
134 views11 pages

Data Structures Worksheet

Uploaded by

SR
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/ 11

MAHARISHI VIDYA MANDIR SR.SEC.

SCHOOL
CHETPET, CHENNAI – 600 031.

DATA STRUCTURES - WORKSHEET

Q.Nos. 1 to 4 are ASSERTION AND REASONING based questions.


Mark the correct choice as:
(a)Both A and R are true and R is the correct explanation for A.
(b)Both A and R are true and R is not the correct explanation for A.
(c)A is true but R is false.
(d)A is false but R is true.

1. ASSERTION(A) : List is an immutable data type.


REASONING(R): When an attempt is made to update the value of an
immutable variable, the old variable is destroyed and a new variable is created
by the same name in memory.

2. ASSERTION (A): If L is a list, then L+=range(5) is an invalid statement.


REASONING (R): Only a list can be concatenated to a list.

3. ASSERTION(A) : A Stack is a LIFO structure.


REASONING(R): Any new element pushed into the stack always gets
positioned at the index after the last existing element in the stack.

4. ASSERTION(A) : The major implementation of using a data structure is to


manage the storage of data in the memory efficiently.
REASONING(R): Data structure refers to the way memory is allocated for
holding data using minimum space. It leads to faster data access during the
execution of the program.

5. Consider the string G20 below:


G20="African Union has been included as a member of the G20".
Write a function lenWords(G20) that takes the string as its parameter and
returns the length of each word of the string as a tuple.

6. Write a function dispBook(BOOKS) in Python, that takes a dictionary BOOKS


as an argument and displays the names in uppercase of those books whose
name starts with a consonant.

For example, Consider the following dictionary BOOKS = {1:"Python",


2:"Internet Fundamentals ", 3:"Networking ", 4:"Oracle sets",
5:"Understanding HTML"}

The output should be:


PYTHON NETWORKING

7. Write a Python Program containing a function FindWord(STRING, SEARCH),


that accepts two arguments : STRING and SEARCH, and prints the count of
occurrence of SEARCH in STRING. Write appropriate statements to call the
function.

For example, if STRING = "Learning history helps to know about history with
interest in history" and SEARCH = 'history'

The function should display:


The word history occurs 3 times.

8. Write a function max_length( ) that takes list of strings as argument and


display the longest string from the list.

9. CBG is a dictionary that stores the name of the country and their respective
Central Banks Governor’s name as shown below.

CBG={"Germany":"JoachimNagel","France":"FrancoisVilleroy de Galhau",
"India":"ShaktikantaDas","UnitedKingdom":"AndrewBailey",
"UnitedStates":"Jer ome Powell"}

Page 1 of 11
Write a function getNames(CBG) that will take the dictionary as its parameter
and will display only those Governor’s names which are more than 20
characters long including the spaces in between.

10.Write a function called letter_freq(my_list) that takes one parameter, a list of


strings(mylist) and returns a dictionary where the keys are the letters from
mylist and the values are the number of times that letter appears in the mylist.

Example, if the passed list is as:


wlist=list(“aaaaabbbbcccdde”)

then it should return a dictionary as


{‘a’:5,’b’:4,’c’:3,’d’:2,’e’:1}

11.Write a function countMy(SUBJECT) in Python, that takes the dictionary,


SUBJECT as an argument and displays the names (in uppercase) of the
subjects whose names are longer than 5 characters.
For example, Consider the following dictionary
SUBJECT={1:"Hindi",2:"Physics",3:"Chemistry",4:"cs",5:"Math"}

The output should be: Hindi Physics Chemistry

12.Write a function, lenLines(STRING), that takes a string as an argument and


returns a tuple containing length of each word of a string.
For example, if the string is "let us learn Python"
the tuple will have ( 3, 2, 5, 6)

13.Write a function sumcube(L) to test if an element from list L is equal to the


sum of the cubes of its digits i.e. it is an "Armstrong number". Print such
numbers in the list.

Example:
If L contains [67,153,311,96,370,405,371,955,407]

The function should print 153,370,371,407

14.Write a function shiftn(L,n), where L is a list of integers and n is an integer.


The function should return a list after shifting n number of elements to the left.

Example: If the list initially contains [2, 15, 3, 14, 7, 9, 19, 6, 1, 10] and n=2
then function should return [3, 14, 7, 9, 19, 6, 1, 10, 2, 15]

If the list initially contains [2, 15, 3, 14, 7, 9, 19, 6, 1, 10] and n=4
then function should return [7, 9, 19, 6, 1, 10, 2, 15, 3, 14]

15.Write a function EVEN_LIST(L), where L is the list of elements passed as


argument to the function. The function returns another list named ‘even list’
that stores even numbers in the list.

For example:
If L contains [1,2,3,4,5,6,7,8]

The even list will have - [2,4,6,8]

16.Write a user defined function change(L) to accept a list of numbers and replace
the numbers in the list with their sum of digits.
Example Input : [32,142,215,26,7]
Output : [5, 7 , 8 , 8, 8,7]

17.“Stack is a linear data structure which follows a particular order in which the
operations are performed”.

What is the order in which the operations are performed in a stack?

Name the list method/function available in Python which is used to remove the
last element from a list implemented as stack.

Page 2 of 11
Also write an example using Python statements for removing the last element
of the list.

18.Give two characteristics and two applications of stack.

19.Write the two operations and their exceptions in stack.

20.Consider the following stack of characters, where STACK is allocated N = 8


memory cells. STACK : A, C, D, F, K,...,...,...
Describe the STACK at the end of the following operations. Here, Pop and Push
are algorithms for deleting and adding an element to the stack.
(i) Pop (STACK, ITEM)
(ii) Pop (STACK, ITEM)
(iii)Push (STACK, L)
(iv) Push (STACK, P)
(v) Pop (STACK, ITEM)
(vi) Push (STACK, R)
(vii) Push (STACK, S)
(viii) Pop (STACK, ITEM)

21.Consider the following sequence of numbers:


1, 2, 3, 4
These are supposed to be operated through a stack to produce the following
sequence of numbers:
2, 1, 4, 3
List the Push and Pop operations to get the required output.

22.Suppose STACK is allocated 6 memory locations and initially STACK is empty


(Top = 0). Give the output of the program segment:
AAA = 4
BBB = 6
Push (STACK, AAA)
Push (STACK, 4)
Push (STACK, BBB +2)
Push (STACK, AAA + BBB)
Push (STACK, 10)
while (Top>0):
Element = STACK.pop( )
print(Element)

23.Consider the following operations are done on a stack. What will be the final
status of the stack after all the operations are performed.
(a) Push(True)
(b) Push(False)
(c) Push(10)
(d) Pop()
(e) Push(50)
(f) Push(70)
(g) Pop()
(h) Pop()

24.Find the final contents of a stack on which the following operations are done.
1. Push(100)
2. Push(200)
3. Push(50)
4. Push(50)
5. Pop()
6. Push()
7. Pop()

25.Consider STACK=['a','b','c','d']
Write the STACK content after each operations:
a) STACK.pop( ) b) STACK.append('e')
c) STACK.append('f') d) STACK.pop( )

26.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.

Page 3 of 11
Display the stack if it has at least one element, otherwise display appropriate
error message.

27.Write a function in Python POP(Arr), where Arr is a stack implemented by a list


of numbers. The function returns the value deleted from the stack.

28.Write a function push (student) and pop (student) to add a new student name
and remove student name from a list student, considering them to act as PUSH
and POP operations of stack Data Structure in Python.

29.Write a function add(bookname) and delete method in python to add


bookname and remove bookname considering them to act as push and pop
operations in stack.

30.Write the functions in Python, Push(Package) and Pop(Package) to add details


of employee containing information (Empid, Ename and Salary) in the form of
tuple in Package and delete a Package from a List of Package Description,
considering them to act as Push and Pop operations of the Stack data structure.

31.Madhu has a message (string) which has a few digits in it. Write a program,
with separate user defined functions to perform the following operations:
● Push the digits in the string into a stack.
● Pop and display the content of the stack.

For example: If the message is :


"CBSE Term 1 2022 exam over!"

The output from the program should be:


22021

32.Thushar received a message(string) that has uppercase and lowercase


alphabets. He wants to extract all the upper case letters separately. Help him
to do his task by performing the following user defined function in Python:
a) Push the uppercase alphabets in the string into a STACK
b) Pop and display the content of the stack.
For example: If the message is “All the Best for your board Examination”
The output should be : E B A

33.Ajay is a student in grade XII who is a budding programmer in Python. His


teacher assigns a task to him: accept a string from the user and create a user-
defined function, INSERT(), that inserts only the uppercase letters present in
the string. He also wants to display the inserted values. Help him by developing
a code to perform the above tasks using data structure.

34.Raghav has created a vocabulary list. You need to help him create a program
with separate user defined functions to perform the following operations based
on this list.
● Traverse the content of the list and push the entries having less than 7
characters into a stack.
● Pop and display the content of the stack.

For Example:
If the sample Content of the list is as follows:
W=[‘Elucidate’, ‘Haughty’, ‘Pacify’, ‘Quip’, ‘Rapport’, ‘Urbane’, ‘Young’,‘Zenith’]

Sample Output of the code should be:


Pacify,Quip,Urbane,Young,Zenith

35.Varun has a list containing integers. You need to help him create a program
with separate user defined functions to perform the following operations based
on this list.
● Traverse the content of the list and push the 2 digit numbers into a stack.
● Pop and display the content of the stack.

For Example:
If the sample Content of the list is as follows:
N=[2, 131, 34, 56, 21, 379, 98, -22, 35, 38]

Page 4 of 11
Sample Output of the code should be:
38 35 -22 98 21 56 34

36.Write the following user defined functions to perform the given operations on
the stack:
Stackpush() – To insert a name of the person into the stack whose age is
greater than 18.

Stackpop() – To pop the elements from the stack and display them. Display
the message “Candidates eligible to vote” after displaying all the names.

37.A nested list contains the data of visitors in a museum. Each of the inner lists
contains the following data of a visitor:
[V_no (int), Date (string), Name (string), Gender (String M/F), Age (int)]

Write the following user defined functions to perform given operations on the
stack named "status":

(i) Push_element(Visitors) - To Push an object containing Gender of visitor who


are in the age range of 15 to 20.

(ii) Pop_element() - To Pop the objects from the stack and count the display
the number of Male and Female entries in the stack. Also, display “Done” when
there are no elements in the stack.

For example: If the list Visitors contains:


[['305', "10/11/2022", “Geeta”,"F”, 35], ['306', "10/11/2022", “Arham”,"M”,
15], ['307', "11/11/2022", “David”,"M”, 18], ['308', "11/11/2022",
“Madhuri”,"F”, 17], ['309', "11/11/2022", “Sikandar”,"M”, 13]]

The stack should contain


F
M
M

The output should be:


Done
Female: 1
Male: 2

38.Write the following functions in Python:


(i) Push(st, expression), where expression is a string containing a valid
arithmetic expression with +, -, *, and / operators, and st is a list representing
a stack. The function should push all the operators appearing in this expression
into the stack st.

(ii) Pop(st) to pop all the elements from the stack st and display them. It
should also display the message 'Stack Empty' when the stack becomes empty.

For example:
If the expression is:
42*5.8*16/24-8+2

Then st should contain


+
-
/
*
*

The output should be:


+ - / * * Stack Empty

39.John has a list containing 10 integers. You need to help him create a program
with separate user defined functions to perform the following operations based
on this list.
● Traverse the content of the list and push the even numbers into a stack.
● Pop and display the content of the stack.

Page 5 of 11
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 22 98 56 34 12

40.A linear stack called Emp contains the following information : Phone number
of Employee, Name of Employee. Write the following methods to perform given
operations on the stack:
(i) Push_element( ) To Push an object containing Phone number of Employee
and Name of Employee into the stack.

(ii) Pop_element( ) To Pop the objects from the stack.

41.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 ‘student’:
(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.

42.Write Addnew(Book) and Remove(Book) functions in python to add a new book


if the book name starts with ‘T’ and to remove a book from a List_of_books,
considering them to act as PUSH and POP operations of the data structure
Stack.

For Example :
If List_of_books contains
[“Wings of fire”, “Don Quixote”, “Alice's Adventures in Wonderland”,
“The Adventures of Huckleberry Finn”, ”The Adventures of Tom Sawyer”,
“Treasure Island”, ”Pride and Prejudice”, “Wuthering Heights”]

Then Book should contain


[“The Adventures of Huckleberry Finn”, ”The Adventures of Tom Sawyer”,
“Treasure Island”]

and after POP operation


the output should be

Treasure Island
The Adventures of Tom Sawyer
The Adventures of Huckleberry Finn

43.Jacob 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:
● Push the keys (name of the student) of the dictionary into a stack, where
the corresponding value (marks) is greater than 75.
● Pop and display the content of the stack.

For example:
If the sample content of the dictionary is as follows:
R={"Hari":76, "Jai":45, "Shiv":89, "Anup":65, "Fin":90, "Tom":82}

The output from the program should be:


Tom Fin Shiv Hari

44.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.

Page 6 of 11
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

45.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

46.A dictionary stu contains rollno and marks of students. Two empty lists
stack_roll and stack_mark will be used as stack. Two functions push_stu()
and pop_stu() are defined and perfom following operations:
(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]

47.Given a Dictionary Stu_dict containing marks of students for three test-series


in the form Stu_ID:(TS1, TS2, TS3) as key-value pairs.
Write a Python program with the following user-defined functions to perform
the specified operations on a stack named Stu_Stk.

(i)Push_elements(Stu_Stk, Stu_dict) : It allows pushing IDs of those students,


from the dictionary Stu_dict into the stack Stu_Stk, who have scored more
than or equal to 80 marks in the TS3 Test.

(ii)Pop_elements(Stu_Stk): It removes all elements present inside the stack


in LIFO order and prints them. Also, the function displays 'Stack Empty' when
there are no elements in the stack. Call both functions to execute queries.

For example:
If the dictionary Stu_dict contains the following data:
Stu_dict ={5:(87,68,89), 10:(57,54,61), 12:(71,67,90), 14:(66,81,80),
18:(80,48,91)}

After executing Push_elements(),


Stk_ID should contain [5,12,14,18]

After executing Pop_elements(),


The output should be:
18
14
12
5
Stack Empty
Page 7 of 11
48.(i)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.

(ii)Write a program in Python to input 5 integers into a list named NUM.

The program should then use the function Push3_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,30]

Then the stack Only3_5 should store


[10,6,18,30]

The output should be displayed as


30 18 6 10 StackEmpty

49.A list items contain the following record as list elements


[itemno, itemname, stock].
Each of these records are nested to form a nested list.

Write the following user defined functions to perform the following on a stack
i) Push(items): It takes the nested list as its argument and pushes a list object
containing itemno and itemname where stock is less than 10.

ii) Popitems(): It pops the objects one by one from the stack and also displays
a message ‘Stack empty’ at the end.

50.A list contains following record of a student: [student_name, age, hostel] Write
the following user defined functions to perform given operations on the stack
named ‘stud_details’:

(i) Push_element() - To Push an object containing name and age of students


who live in hostel “Ganga” 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:
[“Barsat”,17,”Ganga”] [“Ruben”, 16,”Kaveri”] [“Rupesh”,19,”Yamuna”]

The stack should contain


[“Barsat”,17,”Ganga”]

The output should be:


[“Barsat”,17,”Ganga”] Stack Empty

51.A list named as Record contains following format of for students:


[student_name, class, city]. Write the following user defined functions to
perform given operations on the stack named ‘Record’:

(i) Push_record(Record) – To pass the list Record = [ ['Rahul', 12,'Delhi'],


[‘Kohli',11,'Mumbai'], ['Rohit',12,'Delhi'] ] and then Push an object containing
Student name, Class and City of student belongs to ‘Delhi’ to the stack Record
and display and return the contents of stack.

(ii) Pop_record(Record) – To pass following Record [[“Rohit”,”12”,”Delhi”]


[“Rahul”, 12,”Delhi”] ] and then to Pop all the objects from the stack an
d at last display “Stack Empty” when there is no student record in the stack.

Thus the output should be:


[“Rohit”,”12”,”Delhi”] [“Rahul”, 12,”Delhi”] Stack Empty

Page 8 of 11
52.A list contains following record of a customer:
[Customer_name, Phone_number, City]
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 Phone number of
customers who live in Goa 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:


[“Ashok”, “9999999999”,”Goa”] [“Avinash”, “8888888888”,”Mumbai”]
[“Mahesh”,”77777777777”,”Cochin”] [“Rakesh”, “66666666666”,”Goa”]

The stack should contain:


[“Rakesh”,”66666666666”] [“Ashok”,” 99999999999”]

The output should be:


[“Ashok”,”99999999999”] Stack Empty

53.Write a function in Python, Push(Vehicle) where, Vehicle is a dictionary


containing details of vehicles – [Car_Name:Maker]
The function should push the name of car manufactured by ‘TATA’(including
all the possible cases like Tata, TaTa, etc.) to the stack.

For example,
If the dictionary contains the following data:
Vehicle={“Santro”:”Hyundai”,”Nexon”:”TATA”,”Safari”:”Tata”}

The stack should contain


Safari
Nexon

54.Vedika has created a dictionary containing names and marks as key-value


pairs of 5 students. Write a program, with separate user-defined functions to
perform the following operations:
(i) Push the keys (name of the student) of the dictionary into a stack, where
the corresponding value (marks) is greater than 70.

(ii) Pop and display the content of the stack. The dictionary should be as
follows:
d={“Ramesh”:58, “Umesh”:78, “Vishal”:90, “Khushi”:60, “Ishika”:95}

Then the output will be:


Umesh Vishal Ishika

55.BCCI has created a dictionary containing top players and their runs as key
value pairs of cricket team. Write a program, with separate user defined
functions to perform the following operations:
● Push the keys (name of the players) of the dictionary into a stack, where the
corresponding value (runs) is greater than 49.

● Pop and display the content of the stack.

For example: If the sample content of the dictionary is as follows:


SCORE={"KAPIL":40, "SACHIN":55, "SAURAV":80, "RAHUL":35,
"YUVRAJ":110, }

The output from the program should be:


SACHIN SAURAV YUVRAJ

56.A company having dictionary of various Departments and Number of


computers (PC) available as key value pairs. Write a program, with separate
user defined functions to perform the following operations:

● Push the keys (name of the Department) of the dictionary into a stack, where
the corresponding value (Number of PC) is 25 or more.

● Pop and display the content of the stack.

Page 9 of 11
For example:
If the sample content of the dictionary is as follows:
SETUP={"HR":10, "QUALITY":25, "SUPPORT":50, "PRODUCTION":20,
"SUPPLY":25, }

The output from the program should be:


QUALITY SUPPORT SUPPLY

57.Nivedita has started a new year’s resolution to read 12 non fiction books by
the end of 2022. For this purpose she has bought 20 such books. She stores
the data in a dictionary as book_name,rating as key, value pair. Help her out
a bit to organize her collection with help of Stack Data Structure. Write a
program, with separate user defined functions to perform the following
operations:

● Push the keys (book_name) of the dictionary into a stack, where the
corresponding value (rating) are more than 8.

● Pop and display the content of the stack.

For example:
If the sample content of the dictionary is as follows:

B={"AI 2041: Ten Visions for Our Future":7.9, "Beginners: The Transformative
Joy of Lifelong Learning":8.5, "Bravey: Chasing Dreams, Befriending Pain, and
Other Big Ideas":9, "Chatter: The Voice in Our Head, Why It Matters, and How
to Harness It":8.2, "The Code Breaker: Jennifer Doudna, Gene Editing, and the
Future of the Human Race":7.5}

The output from the program should be:

Beginners: The Transformative Joy of Lifelong Learning,


Bravey: Chasing Dreams, Befriending Pain, and Other Big Ideas,
Chatter: The Voice in Our Head, Why It Matters, and How to Harness It

58.Akash has a list containing 10 students marks . You need to help him create a
program with separate user defined functions to perform the following
operations based on this list.

● Traverse the content of the list and push the numbers higher than 33 into a
stack.
● 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:


34,56,79,98,35,38

59.YASH MOTORS have a dictionary of top performer EMPLOYEES and their SALES
as key value pairs of COMPANY. Write a program, with separate user defined
functions to perform the following operations:
● Push the keys (name of the EMPLOYEE) of the dictionary into a stack, where
the corresponding value (SALES) is greater than 500000.
● Pop and display the content of the stack.

For example:
If the sample content of the dictionary is as follows:
SALES={"SUNIL":700000,"ROHIT":400000,"RAJEEV":350000,
"MAYANK":750000, "RAHUL":1000000}

The output from the program should be:


SUNIL MAYANK RAHUL

60.(i)Write the definition of a user defined function PushNV(N) which accepts a


list of strings in the parameter N and pushes all strings which have no words
present in it into a list named NoVowel.

Page 10 of 11
(ii)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 lisr 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 the popped word. When the stack is empty, 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’]

The output should be:


GYM RHYTHM DRY EmptyStack

61.Two lists Lname and Lage contain name of person and age of person
respectively. A list named Lnameage is empty. Write functions as per 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 into the stack Lnameage.

(ii) Pop_na() – It will remove the last pair of name and age and also print name
and age of the removed person. It should also print “underflow” if there is
nothing to remove.

For example, the two lists have the following data:


Lname=[‘Narender’, ‘Jaya’, ‘Raju’, ‘Ramesh’, ’Amit’, ‘Piyush’]
Lage=[45,23,59,34,51,43]

After Push_na, the Lnameage stack contains:


[(‘Raju’,59),(‘Amit’,51)]

The output of first execution of Pop_na() is:


The name removed is Amit
The age of person is 51

*****************

Page 11 of 11

You might also like