Lab 1
Using classes
Submit after the end of the lab session

Overview

For this lab, you will continue practice of using a simple predefined class.

Instructions and questions

  1. Download the zip folder for the lab.
  2. Study the code in files demo.py and plant.py
  3. Run the demonstration functions in demo.py. Explain to yourself what they do and how they work.
  4. In the interactive console, create your own plant object, water it several times and then call needs_water (e.g. my_plant.needs_water()) to see if it works.

Code writing and running

In order to write the functions below, start with the demo.py file and use those functions for suggestions to write the functions below. You should only modify the plant.py file for the last item below. Note the size of the plant after several runs. How does it vary? Why?

  1. Write a function called tend_to_plant. It should take the name of a plant as an argument and create a plant with that name. It should then let that plant grow for 20 days with each day consisting of the following:
    • Water the plant (water).
    • Count the day off (tick_day).

    After 20 days, the function should report (use print) the size of the plant.

  2. Write a function care_compare. It should take the names (strings) of two plants as arguments. It should then create two plant objects and grow them together for twenty days. However, it should follow different watering strategies:
    • First plant: only water if it needs it
    • Second plant: only water it every other day

    After twenty days, it should report the sizes of the plants.

  3. Run care_compare multiple times, enough for you to feel confident that you understand how the two care strategies compare. Summarize the difference.
  4. Will the water level for a plan ever be less than 0? How can you be sure? To ensure that the water level is never less than zero, add an assert statement to the tick_day method. Think carefully where the assert statement should go.

Deliverable

Create a pdf file that contains the following:

  1. A statement that summarizes your completion of the lab. As appropriate, the statement should include the following:
    • Who you worked with on the lab
    • Any difficulties you encountered
    • How you tested it (output can be provided at the end of your file)
    • Responses to questions
  2. Your clearly labeled answers to explanations and questions
  3. A summary of the files included in the zip folder
  4. Demonstrations that show that your code works

Put your files in a folder, zip it and submit it under Lab 1 on D2L. Check that your submitted zip file is complete.

Grading

The lab is worth 3 points. Your lab submission will be graded using the following rubric:

  • + .5 --- Your submission is clearly formatted.
  • + .5 --- Your submission includes a summary statement and includes how you collaborated.
  • + .5 --- Your statement addresses all questions.
  • + .5 / 1.0 --- You submitted most of the lab (0.5) or you submitted all of the lab (1.0).
  • + .5 --- Your lab submission is generally correct.

Labs are worth three points. Fraction scores will be rounded up to the nearest whole point.