Given a base Plant class and a derived Flower class, write a program to create a list called my_garden. Store objects that belong to the Plant class or the Flower class in the list. Create a function called print_list(), that uses the print_info() instance methods defined in the respective classes and prints each element in my_garden. The program should read plants or flowers from input (ending with -1), add each Plant or Flower to the my_garden list, and output each element in my_garden using the print_info() function. Note: A list can contain different data type and also different objects. Python for this.
10.27 LAB: Plant information
Given a base Plant class and a derived Flower class, write a program to create a list called my_garden. Store objects that belong to the Plant class or the Flower class in the list. Create a function called print_list(), that uses the print_info() instance methods defined in the respective classes and prints each element in my_garden. The program should read plants or flowers from input (ending with -1), add each Plant or Flower to the my_garden list, and output each element in my_garden using the print_info() function.
Note: A list can contain different data type and also different objects.
Python for this.
![LAB
10.27.1: LAB: Plant information
0/ 10
АCTIVITY
main.py
Load default template.
1 class Plant:
def _init_(self, plant_name, plant_cost):
self.plant_name = plant_name
self.plant_cost = plant_cost
2
4
5
def print_info(self):
print('Plant Information:')
print('
print('
7
Plant name:', self.plant_name)
Cost:', self.plant_cost)
10
11 class Flower (Plant):
def init_(self, plant_name, plant_cost, is_annual, color_of_flowers):
Plant._init_(self, plant_name, plant_cost)
self.is_annual = is_annual
self.color_of_flowers = color_of_flowers
12
13
14
15
16
def print_info(self):
print('Plant Information:')
print('
print('
print('
print('
17
18
Plant name:', self.plant_name)
Cost:', self.plant_cost)
Annual:',self.is_annual)
Color of flowers:',self.color_of_flowers)
19
20
21
22
23
24 # TODO: Define the print_list() function that prints a list of plant (or flower) objects
25
26 it name =
= "_main_":
27
28
# TODO: Declare a list called my_garden that can hold object of type plant
29
зе
user_string =
input()
31
while user_string != '-1':
# TODO: Check if input is a plant or fLower
32
33
Split the user_string input into variables - plant_name, plant_cost, color_of_fLowers, is_annual
store as a pLant object or flower object
Add to the List my_garden
34
23
35
23
36
user_string = input()
37
38
39
# TODO: Call the print_list() function to print my_garden
mm m m mmm](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa9cfe732-6955-4d13-a021-51c952b6f3c5%2F1cffb5bf-9e88-4b30-b3c1-6dc75be20ee1%2Fnym3yxo_processed.png&w=3840&q=75)
![Ex. If the input is:
plant Spirea 10
flower Hydrangea 30 false lilac
flower Rose 6 false white
plant Mint 4
-1
the output is:
Plant Information:
Plant name: Spirea
Cost: 10
Plant Information:
Plant name: Hydrangea
Cost: 30
Annual: false
Color of flowers: lilac
Plant Information:
Plant name: Rose
Cost: 6
Annual: false
Color of flowers: white
Plant Information:
Plant name: Mint
Cost: 4](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa9cfe732-6955-4d13-a021-51c952b6f3c5%2F1cffb5bf-9e88-4b30-b3c1-6dc75be20ee1%2Fzgwzayg_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
How would you add "1,2,3,4" for each result?
"Plant 1 Information"
"Plant 2 Information"
etc.
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)