Kristina D.

asked • 11/17/20

Programming with Python: Classes

Hi! Could somebody help me with this assignment? It's for my programming class and I am required to create a class with multiple functions.


  1. Create a class named Plant
  2. In the __init__ function of Plant have a single parameter (other than self) named name. Set the name attribute of the Plant (i.e., self.name) to the value of the name parameter. Set a state attribute of the Plant to "alive"
  3. Create a water function of the Plant class which will check the value of the PLant's (i.e., self's) state attribute and set it to "sated" if it was "alive", or set it to "dead" if it was "sated", or do nothing otherwise
  4. Create a place_in_sun function of the Plant class which will check the value of the Plant's (i.e., self's) state attribute and set it to "alive" if it was "sated", or set it to "dead" if it was "alive", or do nothing otherwise
  5. Create a __str__ function of the Plant class which will return "Plant[name=name, state=state]" with the Plant's (i.e., self's) name and state attribute values substituted for name and state
  6. Outside the definition of the Plant class, create three Plant objects/values in three separate variables (giving each a unique name). Call the water function twice on the second Plant, call the place_in_sun function once on the third Plant
  7. Print the three Plant objects, each on a separate line

1 Expert Answer

By:

Patrick B. answered • 11/17/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.