Question

Using Python, Write a class called Plant that has variables height, sunlight, and water, and has...

Using Python,

  • Write a class called Plant that has variables height, sunlight, and water, and has getters and setters for these variables and a function called Grow, which multiplies sunlight and water together and adds it to height
0 0
Add a comment Improve this question Transcribed image text
Answer #1
class Plant:
    def __init__(self, height=0, sunlight=0, water=0):
        self.height = height
        self.sunlight = sunlight
        self.water = water

    def get_height(self):
        return self.height

    def get_sunlight(self):
        return self.sunlight

    def get_water(self):
        return self.water

    def set_height(self, height):
        self.height = height

    def set_sunlight(self, sunlight):
        self.sunlight = sunlight

    def set_water(self, water):
        self.water = water

    def Grow(self):
        self.height += self.sunlight * self.water


# Testing the class here. ignore/remove the code below if not required
plant = Plant()
plant.set_height(4)
plant.set_water(2)
plant.set_sunlight(3)
print(plant.get_height())
plant.Grow()
print(plant.get_height())

4 10 Process finished with exit code 0

Add a comment
Know the answer?
Add Answer to:
Using Python, Write a class called Plant that has variables height, sunlight, and water, and has...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT