Python | CSV and Excel exercise | Open a workbook of plants and find all the ones in stock

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Software ==> Python  (28 exercises)
Version ==> Latest version
Topic ==> CSV and Excel  (2 exercises)
Level ==> Average difficulty
Subject ==> Python training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

The above folder contains a workbook listing plants, some of which are not in stock:

Not in stock plants

The plants not in stock have the value No in column H (highlighted here in green).

Import the openpyxl module.  Write a macro which starts on cell A2 and keeps going down until it hits a blank cell (ie one whose value is None).  For each cell your macro should:

  1. Check the value of the cell offset 0 rows down and 7 columns to the right of the current one.
  2. If this is No your macro should print out this plant's name.

A typical output from your macro when it's finished might be something like this:

List of plants

The openpyxl module tries to mimic Excel, but sometimes throws up warnings like this when it can't.

Close down your program, musing to yourself on whether it's really easier to do things like this in Python and not Excel!

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post