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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
Transcribed Image Text: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
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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

How would you add "1,2,3,4" for each result?

"Plant 1 Information"

"Plant 2 Information" 

etc.

 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education