KnowledgeBoat Logo
|

Computer Science

Write AddCustomer(Customer) and DeleteCustomer(Customer) methods in Python to add a new Customer and delete a Customer from a List of CustomerNames, considering them to act as push and pop operations of the Stack data structure.

Python

Python Stack

7 Likes

Answer

def AddCustomer(Customer):
    Customer_name = input("Enter the customer name: ")
    Customer.append(Customer_name)

def DeleteCustomer(Customer):
    if Customer == []:
        print("Customer list is empty")
    else: 
        print("Deleted Customer name:", Customer.pop())

Customer = []

AddCustomer(Customer)
AddCustomer(Customer)
AddCustomer(Customer)
print("Initial Customer Stack:", Customer)

DeleteCustomer(Customer)
print("Customer Stack after deletion:", Customer)

Output

Enter the customer name: Anusha
Enter the customer name: Sandeep
Enter the customer name: Prithvi
Initial Customer Stack: ['Anusha', 'Sandeep', 'Prithvi']
Deleted Customer name: Prithvi
Customer Stack after deletion: ['Anusha', 'Sandeep']

Answered By

2 Likes


Related Questions