Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Cells
Summary

Instruction

Good job! Now, if we print a cell from the calendar worksheet, we see something similar to:

<Cell "calendar".A1>

This means we've accessed the A1 cell in the calendar worksheet. But we can"t see the contents of the cell. How do we go about accessing cell contents?

We can access the value property in the same way we've accessed the title property of a worksheet. Let's go back to sweets_ws for this. Suppose we've already selected our cell, A1. We can then use cell.value to acquire the value held in that particular cell:

sweets_ws["A1"].value

When accessing a cell value, it's important to note that openpyxl automatically converts the value of the given cell to the appropriate data type. For example, if the value in A1 is the number 1.000, Python will automatically treat that value as an integer.

Exercise

You can see that we've loaded the summary worksheet for you. It contains the following columns: date, kcal, proteins, carbohydrates, and fats.

Your task is to find the number of calories consumed in three consecutive days and assign the value to the kcal_sum variable. To get the number, access the B2, B3, and B4 cells and add their values together. Print the final value.