Loading...
Loading...
Loading...
A shop has this price list: pen 10, book 50, bag 120, laptop 45000. Read a product name. Print Price: followed by its price. If the product is not in the list, print Product not found.
Read the price with [] and catch the error.
Price: <price> or Product not found.Example 1
Input
book
Output
Price: 50
A product in the list.
Example 2
Input
phone
Output
Product not found
A product that is missing.
Try the problem first. Open one hint at a time.
A dictionary lookup with a missing key raises KeyError.
Keep the dictionary in the program and look up the name inside try.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor