Implement add_recipe, remove_recipe, get_total_discount, and then add support for undo and redo of cart operations.
Implement a cart object that supports adding and removing recipes, computing the current total discount, and undoing or redoing the most recent cart changes. Assume each recipe has a unique recipe_id and a numeric discount value.
add_recipe(recipe_id, discount) adds or updates a recipe in the cart.remove_recipe(recipe_id) removes a recipe if it exists.get_total_discount() returns the sum of discounts for all recipes currently in the cart.undo() reverts the most recent add or remove operation.redo() reapplies the most recently undone operation.If an operation cannot be applied, it should do nothing. Return the current total discount after each get_total_discount() call.
def manage_cart(operations):