A school stores records of Class XII students using a list that contains multiple lists as its elements. The structure of each such element is [Student_Name, Marks, MainSubject]. Crate user-defined functions to perform the operations as mentioned below:
(a) Push_student(): To push the Student_Name and Marks of all those students, who have Science as MainSubject, into a Stack StudentInfo
(b) Pop_student(): To delete all items (one at a time) from the stack StudentInfo in LIFO order and display them. Also display "Empty Stack" when there are no items remaining in the stack.
For Example:
If the stored information is:
[['Akansha',98,"Mathematics"],["Priti",96,"Science"],["Garima",99,"Science"],["Ayushi",78,"English"]]
The stack should contain:
[['Priti', 96], ['Garima', 99]]
The output should be:
["Garima",99]
["Priti",96]
Empty Stack
Solution:
def Push_student():
for S in L:
if S[2]=="Science":
StudentInfo.append([S[0],S[1]])
print(StudentInfo)
def Pop_student():
while StudentInfo!=[]:
print(StudentInfo.pop())
else:
print("Stack is Empty")
Push_student()
Pop_student()
No comments:
Post a Comment