Q. Write a function PUSH( stk ), where stk is a stack implemented as a list with individual elements as tuples (Admno, Name, Marks). Push elements of stack stk to two different stacks named PASS and FAIL by checking marks (passing marks are >=35). Display the stacks PASS and FAIL if it has at least one element otherwise display an appropriate message.
Answer :-
def Push ( stk ): Pass = [] Fail = [] for i in stk : if i[2] >= 35 : Pass += [ i ] else : Fail += [ i ] print ("Pass :- ",Pass) print("Fail :- ",Fail) stk = eval(input("Enter list of tuples of Student :- ")) if len(stk)==0: print("Enter at list one record.") else : Push( stk )
Output :-
Enter list of tuples of Student :- [ ( 123,"Path",95 ), ( 456,"Walla",12) ]
Pass :- [(123, 'Path', 95)]
Fail :- [(456, 'Walla', 12)]
Pass :- [(123, 'Path', 95)]
Fail :- [(456, 'Walla', 12)]
>>>
Enter list of tuples of Student :- []
Enter at list one record.
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )