KEMBAR78
Assignment Stack | PDF | Computer Engineering | Computer Programming
0% found this document useful (0 votes)
50 views2 pages

Assignment Stack

The document outlines a series of programming assignments focused on stack operations using Python. It includes tasks such as pushing and popping student records, managing employee details based on salary, and handling bakery items and travel data with specific conditions. Each assignment requires the implementation of user-defined functions to manipulate stacks and handle various data types effectively.

Uploaded by

Jitesh Pahuja
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)
50 views2 pages

Assignment Stack

The document outlines a series of programming assignments focused on stack operations using Python. It includes tasks such as pushing and popping student records, managing employee details based on salary, and handling bakery items and travel data with specific conditions. Each assignment requires the implementation of user-defined functions to manipulate stacks and handle various data types effectively.

Uploaded by

Jitesh Pahuja
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/ 2

ASSIGNMENT : STACK

1. A list contains following record of a student: [Rno, Name, Dob, Class].Write the following user defined
functions to perform given operationson 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.
2. 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
a) Push_na() :- it will push the tuple containing pair of name and age from Lname and Lage
whose age is above 50
b) 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
The age of person is 51
3. 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 perform 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}

4. A list contains following record of a student in the form of a list containing student_name, marks,
subject
Write the following user defined functions to perform given operations on the stack named ‘status’:
a) Push_element(status,student) –this function takes the stack status and new students record as
argument and push an new student record containing name and marks of a student who scored
more than 75 marks in ‘CS’ to the stack
b) Pop_element(status) –this function pops the topmost record from the stack and returns it.if the
stack is emplty the function sould display “underflow”
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”]

AMIT KUMAR KUSHWAHA (9891145409) Page 1


[“Sidhi”,”99”]
Stack Empty
5. 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
6. 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
7. 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 :[['ravi',26],['raman',36], ['chaman',56]]
The Stack should contain : Ravi
Raman
The output should be : The number of elements in stack is : 2
8. A list, NList contains following record as list elements: [City, Country, distance from Delhi]
Each of these records are nested together to form a nested list. Write the following user defined
functions in Python to perform the specified operations on the stack named travel.
(i) Push_element(NList): It takes the nested list as an argument and pushes a list object containing
name of the city and country, which are not in India and distance is less than 3500 km from Delhi.
(ii) Pop_element(): It pops the objects from the stack and displays them. Also, the function should
display “Stack Empty” when there are no elements in the stack.
For example: If the nested list contains the following data:
NList=[["New York", "U.S.A.", 11734],
["Naypyidaw", "Myanmar", 3219],
["Dubai", "UAE", 2194],
["London", "England", 6693],
[ "Gangtok", "India", 1580],
["Columbo", "Sri Lanka", 3405]]
The stack should contain:
['Naypyidaw', 'Myanmar'],
['Dubai', 'UAE'],
['Columbo', 'Sri Lanka']
The output should be:
['Columbo', 'Sri Lanka']
['Dubai', 'UAE']
['Naypyidaw', 'Myanmar']
Stack Empty

AMIT KUMAR KUSHWAHA (9891145409) Page 2

You might also like