CBSE Class 12 Computer Science Question 40 of 63

Data Structures in Python — Question 14

Back to all questions
14
Question

Question 14

Write AddClient(Client) and DeleteClient(Client) methods in Python to add a new client and delete a client from a list client name, considering them to act as insert and delete operations of the Queue data structure.

Solution
def AddClient(client):
    client_name = input("Enter client name: ")
    client.append(client_name)

def DeleteClient(client):
    if client == []:
        print("Queue is empty")
    else:
        print("Deleted client:", client.pop(0))

client = []

AddClient(client)
AddClient(client)
AddClient(client)
print("Initial Client Queue:", client)

DeleteClient(client)
print("Client Queue after deletion:", client)
Output
Enter client name: Rahul
Enter client name: Tanvi
Enter client name: Vidya
Initial Client Queue: ['Rahul', 'Tanvi', 'Vidya']
Deleted client: Rahul
Client Queue after deletion: ['Tanvi', 'Vidya']
Answer