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
  • (python) [26] Write a sub class called "patient" for the following class with accessors and mutators...

    (python) [26] Write a sub class called "patient" for the following class with accessors and mutators for property called name. Introduce a private property called "sickness" with setters and getters in the sub class class person: def __init_(self): self._name

  • Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredi...

    Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredients (an array of up to 10 ingredients, such as ham, capicola, American cheese, lettuce, tomato) -condiments (an array of up to 5 condiments, such as mayonnaise, oil, vinegar and mustard) Create a two argument constructor Write the getters and setters for the instance variables Override the toString method using the...

  • Write a class called Book that has two private member variables called page (integer) and topic...

    Write a class called Book that has two private member variables called page (integer) and topic (string). It also has a static private member variable called count (integer). This class has only one constructor with default argument for page and topic. Write this constructor. Also overload the addition operator for this class such that it will add an integer value to the page variable of the book. For example when in main we say: book2 = book1 + 4; then...

  • 2. Write a class called ATMTransaction. This class has a variable balance and account number. It...

    2. Write a class called ATMTransaction. This class has a variable balance and account number. It has three methods, checkBalance, deposit and withdraw along with constructors getters and setters and a toString. Write a program that creates an object of this class. I should be able to deposit and withdraw from my account number based on my balance , but i shouldnt be able to change my account number. Look for loopholes in your program, test it correctly, your balance...

  • Create a class called Pair that has two public integer member variables named "a" and "b",...

    Create a class called Pair that has two public integer member variables named "a" and "b", and a public member function named sum() that has no arguments but adds the two member variables together and returns their sum.

  • C++ Program 3 Create a class Person Include three(3) variables: firstName, lastName, YearOfBirth Write default and...

    C++ Program 3 Create a class Person Include three(3) variables: firstName, lastName, YearOfBirth Write default and parameterized constructors Write getters and setters for each variable. Declare 2 instances of the person class P1 and P2, one for both default and parm constructors Declare ptrPerson1 and ptrPerson2. Assign ptrPerson1 address of P1 Assign ptrPerson2 address of P2 Call all the getters and setters using the ARROW notation to test the class. Example:    ptrP1à getFirstName()

  • python3 d. Make a class called "bad_math' that has 2 variables, a and b. Include all...

    python3 d. Make a class called "bad_math' that has 2 variables, a and b. Include all the necessary functions, but also write a function called bad_addition' that adds the e. Using the above class, write code that creates a new "bad_math' object, sets a and b to 5 and 12, and then calls 'bad addition' on the object. f. Write code that asks for number input from the user until they type in a 0, then prints out the sum...

  • Using Python Write the following well-documented (commented) program. Create a class called Shape that has a...

    Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....

  • Python Program: Design a class Write a class called Sport that has a single attribute teamSize....

    Python Program: Design a class Write a class called Sport that has a single attribute teamSize. Write a parametrized constructor to initialize the object. Inherit this class into another class called Football, with attributes teamName and numChampionships. Write a parametrized constructor to initialize this object and a printStuff function. Then, create an object of Football and print the values. Sample Run: The values are: Team Size: 45 Team Name: Florida State Seminoles National Champions: 3 times

  • Design and implement a C++ class called Date that has the following private member variables month...

    Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...

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