Listing 06-21: Obtaining the price with a dictionary

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 06\06.21 - Obtaining the price with a dictionary.py
# Description: Obtaining the price with a dictionary
##############################################################################

table = {"Lettuce": 0.45,
         "Potato": 1.20,
         "Tomato": 2.30,
         "Beans": 1.50}
while True:
    product = input("Enter product's name, end to exit:")
    if product == "end":
        break
    if product in table:
        print(f"Price {table[product]:5.2f}")
    else:
        print("Product not found!")
Click here to download the file