#! python3
# P04_updateProduce.py - Corrects costs in produce sales spreadsheet.
#
# Note:
# - The produceSales.xlsx workbook can be downloaded from
#   https://nostarch.com/automatestuff/

import openpyxl

wb = openpyxl.load_workbook("produceSales.xlsx")
sheet = wb.get_sheet_by_name("Sheet")

# The produce types and their updated prices
PRICE_UPDATES = {"Garlic": 3.07,
                 "Celery": 1.19,
                 "Lemon": 1.27}

# Loop through the rows and update the prices
for rowNum in range(2, sheet.max_row):  # skip the first row
    produceName = sheet.cell(row=rowNum, column=1).value
    if produceName in PRICE_UPDATES:
        sheet.cell(row=rowNum, column=2).value = PRICE_UPDATES[produceName]

wb.save("updatedProduceSales.xlsx")

#! python3
# P04_updateProduce.py - Corrects costs in produce sales spreadsheet.
#
# Note:
# - The produceSales.xlsx workbook can be downloaded from
#   https://nostarch.com/automatestuff/

import openpyxl

wb = openpyxl.load_workbook("produceSales.xlsx")
sheet = wb["Sheet"]

# The produce types and their updated prices
PRICE_UPDATES = {"Garlic": 3.07,
                 "Celery": 1.19,
                 "Lemon": 1.27}

# Loop through the rows and update the prices
for rowNum in range(2, sheet.max_row):  # skip the first row
    produceName = sheet.cell(row=rowNum, column=1).value
    if produceName in PRICE_UPDATES:
        sheet.cell(row=rowNum, column=2).value = PRICE_UPDATES[produceName]

wb.save("updatedProduceSales.xlsx")

Update P04_updateProduce fixed warning by changing depreciated method