Q. FLYAIR Airlines has grown big and touches more than 140 destinations worldwide, offering excellent service to its passengers. To provide latest information to its customers at the click of a button, the company offers computerized processing of passenger details.
Write a Python program comprising methods / functions to add or delete a passenger's name from the list of passengers, considering them as insert and delete operations of the Queue data structure.
Answer :-
def INSERT (Q): pname = input("Enter the name of the passenger to be added : ") Q.append(pname) def DEL (Q): if Q != [] : pname = Q.pop(0) print ("Passenger data deleted ") else: print ("Empty queue. No Passenger details") def SHOW (a) : print (Q) Q = [] while True: Option = input ("I:INSERT D:DEL S:SHOW E:EXIT ") if Option == "I": INSERT (Q) elif Option == "D": DEL (Q) elif Option == "S": SHOW (Q) elif Option == "E": print ("Happy and Safe Journey") break else: print ("Wrong Option")
Output :-
I:INSERT D:DEL S:SHOW E:EXIT I
Enter the name of the passenger to be added : RAMAN
I:INSERT D:DEL S:SHOW E:EXIT I
Enter the name of the passenger to be added : RAHUL
I:INSERT D:DEL S:SHOW E:EXIT I
Enter the name of the passenger to be added : RAJESH
I:INSERT D:DEL S:SHOW E:EXIT S
['RAMAN', 'RAHUL', 'RAJESH']
I:INSERT D:DEL S:SHOW E:EXIT D
Passenger data deleted
I:INSERT D:DEL S:SHOW E:EXIT S
['RAHUL', 'RAJESH']
I:INSERT D:DEL S:SHOW E:EXIT E
Happy and Safe Journey
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )