Manage the Shopping Cart

Given an empty shopping cart, you are asked to implement a manage_cart function that would be called n times to modify and view the shopping cart. There are 3 allowed operations:
  • add: Add an item to the cart (an item is a string). If the item is already in the cart, the program should print <ITEM> is already in the cart.
  • remove: Remove an item from the cart (an item is a string). If the item is not in the cart, the program should print <ITEM> was not found.
  • view: Print Current cart: <ITEM1>, <ITEM2>, .... If the cart is empty, it should just print Current cart: .
Here <ITEM>, <ITEM1>, and <ITEM2> are the items (the strings) currently in the shopping cart or passed as an argument.
 
The manage_cart function should have 2 parameters:
  1. operation (positional): One of add, remove, or view.
  1. item։ An optional keyword argument that defaults to None.
 
Tip
Store a global cart variable that would store the current contents of the cart.
Input
Output
2 add Banana view
Current cart: Banana
7 add Apple add Banana view remove Apple add Banana view remove Apple
Current cart: Apple, Banana Banana is already in the cart Current cart: Banana Apple was not found

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue