Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Looking for output 

16.11 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 types and also different objects.
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 1 Information:
Plant name: Spirea
Cost: 10
Plant 2 Information:
Plant name: Hydrangea
Cost: 30
Annual: false
Color of flowers: lilac
Plant 3 Information:
Plant name: Rose
Cost: 6
Annual: false
Color of flowers: white
Plant 4 Information:
Plant name: Mint
Cost: 4
expand button
Transcribed Image Text:16.11 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 types and also different objects. 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 1 Information: Plant name: Spirea Cost: 10 Plant 2 Information: Plant name: Hydrangea Cost: 30 Annual: false Color of flowers: lilac Plant 3 Information: Plant name: Rose Cost: 6 Annual: false Color of flowers: white Plant 4 Information: Plant name: Mint Cost: 4
1 class Plant:
2 def __init__(self, plant_name, plant_cost):
3
self.plant_name plant_name
self.plant_cost = plant_cost
4
5
6
7
8
9
1
2
3
4
5
6
def print_info(self):
7
8
9
0
1
2
3
4
5
6
7
print(f' Plant name: { self.plant_name }')
print(f' Cost: {self.plant_cost }')
5
6
7
8
9
0
1
2 # TODO: Define the print_list() function that prints a list of plant (or flower) objects
3
4 if __name__ == "__main__":
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
def print_info(self):
print(f' Plant name: { self.plant_name }')
Cost: {self.plant_cost }')
print(f'
print(f' Annual: {self.is_annual }')
print(f' Color of flowers: {self.color_of_flowers }')
# TODO: Declare a list called my_garden that can hold object of type plant
user_string
input()
=
while user_string != '-1':
# TODO: Check if input is a plant or flower
#
#
#
Split the user_string input into variables - plant_name, plant_cost, color_of_flowers, is_ar
Store as a plant object or flower object
Add to the list my_garden
user_string
input()
# TODO: Call the print_list() function to print my_garden
=
expand button
Transcribed Image Text:1 class Plant: 2 def __init__(self, plant_name, plant_cost): 3 self.plant_name plant_name self.plant_cost = plant_cost 4 5 6 7 8 9 1 2 3 4 5 6 def print_info(self): 7 8 9 0 1 2 3 4 5 6 7 print(f' Plant name: { self.plant_name }') print(f' Cost: {self.plant_cost }') 5 6 7 8 9 0 1 2 # TODO: Define the print_list() function that prints a list of plant (or flower) objects 3 4 if __name__ == "__main__": 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 def print_info(self): print(f' Plant name: { self.plant_name }') Cost: {self.plant_cost }') print(f' print(f' Annual: {self.is_annual }') print(f' Color of flowers: {self.color_of_flowers }') # TODO: Declare a list called my_garden that can hold object of type plant user_string input() = while user_string != '-1': # TODO: Check if input is a plant or flower # # # Split the user_string input into variables - plant_name, plant_cost, color_of_flowers, is_ar Store as a plant object or flower object Add to the list my_garden user_string input() # TODO: Call the print_list() function to print my_garden =
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY