Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THE QUESTION: THIS IS MY CODE: class Plant: def __init__(self, plant_name, plant_cost): self.plant_name = plant_name self.plant_cost = plant_cost def print_info(self): print('Plant name:', self.plant_name) print(' Cost:',

THE QUESTION:

image text in transcribed

THIS IS MY CODE:

class Plant: def __init__(self, plant_name, plant_cost): self.plant_name = plant_name self.plant_cost = plant_cost

def print_info(self): print('Plant name:', self.plant_name) print(' Cost:', self.plant_cost)

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('Plant name:', self.plant_name) print(' Cost:', self.plant_cost) print(' Annual:', self.is_annual) print(' Color of flowers:', self.color_of_flowers)

# print_list() function def print_list(plant_names): for i, plant in enumerate(plant_names): print('Plant', i + 1, 'Information:') plant.print_info() print()

if __name__ == "__main__": # declare list named my_garden to hold plant my_garden = [] user_string = input()

while user_string != '-1': info = user_string.split() if info[0] == "plant": plant_name = info[1] plant_cost = int(info[2]) new = Plant(plant_name, plant_cost)

if info[0] == "flower": plant_name = info[1] plant_cost = int(info[2]) is_annual = (info[3] == "True") color_of_flowers = info[4] new = Flower(plant_name, plant_cost, is_annual, color_of_flowers)

my_garden.append(new) user_string = input()

# calling print_list() function print_list(my_garden)

THESE ARE THE ERRORS:

image text in transcribed

Please let me know if you can help!

Thank you!

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 0 , that uses the printinfo 0 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 zyBooks My library > ITS 148: Problem Solving and the Programming Process II home > 13.9: LAB: Plant information

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

To realize business outcomes before and after HRM adoption.

Answered: 1 week ago