Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TREE CLASS: class Tree: def __init__(self,name,length,b_color,l_color,angle): self.name=name self.length=length self.b_color=b_color self.l_color=l_color self.angle=angle def __str__(self): return self.name def __repr__(self): return 'Tree({}, {}, {}, {}, {})'.format(self.name,self.length,self.b_color,self.l_color,self.angle) Write a

image text in transcribed

image text in transcribedTREE CLASS:

class Tree: def __init__(self,name,length,b_color,l_color,angle): self.name=name self.length=length self.b_color=b_color self.l_color=l_color self.angle=angle def __str__(self): return self.name def __repr__(self): return 'Tree("{}", {}, {}, {}, {})'.format(self.name,self.length,self.b_color,self.l_color,self.angle)

Write a class named Forest which represents a set of specific trees. The Forest class tracks the set of trees, along with how old each tree is. You will also need to include your Tree class from the previous question in the answer box. You must complete the following functions in the Forest class: _init_o) The init function should take as a parameter a list of tuples, where each Tuple contains a Tree and an associated age. __str_0 The str function should print the total number of trees within the forest, and then summarize what each one is. Consider the following code fragment: ash = Tree("Ash", 4, (150,75,0), (0,255,0), 30) my_forest = Forest([(ash, 4), (ash, 7)]) print(my_forest) The output should be: Forest containing 2 trees: 4 year old Ash 7 year old Ash add_tree() The add_tree function takes as parameters an instance of the Tree class and an age, and appends to the Forest a new tree of that species. Consider the following code fragment: ash = Tree("Ash", 4, (150,75,0), (0,255,0), 30) my_forest = Forest([(ash, 4), (ash, 7)]) my_forest.add_tree(ash, 6) print(my_forest) The output should be: Forest containing 3 trees: 4 year old Ash 7 year old Ash 6 year old Ash

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

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions