Final answer:
The question pertains to implementing a program with parallel lists in Python to match coffee add-in names with their prices, or display a message if the item is not found. The method includes using index() to retrieve data from lists and handling exceptions for non-existent items.
Step-by-step explanation:
The question is focused on using parallel lists in Python to manage and retrieve data. In Python, parallel lists refer to having multiple lists where each list holds related information and all lists are indexed in a synchronized manner. For example, you might have a list of product names and a corresponding parallel list with product prices. When a user queries for a specific product, such as a coffee add-in at the Jumpin’ Jive Coffee Shop, the program uses the index of that product name to find the exact price in the parallel price list. If the product is not found, the program returns a message indicating the item is not available.
To implement this, you can use the index() method to find the index of the given item in one list and then use that index to retrieve the corresponding item from another list. If the item is not found in the first list, catching the ValueError exception will allow the program to print the appropriate error message.
Here is a basic example of how the Python code could look:
product_names = ["Espresso", "Americano", "Latte"]
product_prices = [1.50, 2.00, 2.25]
try:
item_index = product_names.index("Latte")
print(f"{product_names[item_index]}: ${product_prices[item_index]}")
except ValueError:
print("Sorry, we do not carry that.")
Ensure to handle user input and match it against the list of product names accurately bearing in mind any case sensitivity or input variations.