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

Instruction

As we've already mentioned, we can access our cell data in two ways. One is similar to a dictionary:

sweets_ws["A1"]

And one uses the cell method:

sweets_ws.cell(row=1, column=1)

The cell method is particularly useful when it comes to iterating over multiple cells. For instance, we can easily get data from column 1, rows 1 to 10, if we use this method in a for loop:

for row in range(1, 11):
  print(sweets_ws.cell(row=row, column=1).value)

This allows us to easily access and manipulate values in a column.

Exercise

Access all the caloric values for January 1 (column 2, rows 2 to 6), add them together, and save the result in the calorie_intake variable. Print the value. We've already loaded the appropriate spreadsheet for you.

01-01

Stuck? Here's a hint!

Create the variable and initialize it with 0.

Then, iterate over rows and add the value of a given cell to the variable. The range() function may come in handy, but remember that the first value provided in the range() function is inclusive and the second one is exclusive. The following loop will print the values from cells one to five:

from i in range(1, 6):
  print(i)