
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Looking for output

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

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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images

Knowledge Booster
Similar questions
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY