Question: Question text Complete the function load_forest_from_file() specified in A1.py It should take as parameters the name of a file containing a forest definition and the

Question text

Complete the function load_forest_from_file() specified in A1.py

It should take as parameters the name of a file containing a forest definition and the list of available tree species and return an instance of the Forest class containing the set of trees and corresponding ages specified in the file. Trees should be identified by matching based on their name.

In some cases, the Forest file may name trees that are not present in the currently loaded Trees file. Whenever this occurs, the program should print that that tree does not exist, and the line should be skipped.

If the file does not exist, the function should print that the file is not found and return None.

You will need to include your class definitions for Tree and Forest from parts 1 and 2, and your load_trees_from_file() function from part 3 in your answer.

Consider the following code fragment:

trees = load_trees_from_file('Trees.txt') forest = load_forest_from_file('Forest.txt', trees) print(forest)

If the file Trees.txt contains the following lines:

Ash,10,150,75,0,0,255,0,30 Oak,12,130,70,0,0,200,0,45 

And the file Forest.txt contains the following lines:

 
Ash,4 Ash,6 Oak,8 Beech,3 Pine,5

The output will be:

 

Tree Beech does not exist! Tree Pine does not exist! Forest contains 3 trees: 4 year old Ash 6 year old Ash 8 year old Oak

class Forest:

https://www.chegg.com/homework-help/questions-and-answers/write-class-named-forest-represents-set-specific-trees-forest-class-tracks-set-trees-along-q44173162?trackid=Y9J5FEzO

Complete the function load_forest_from_file() specified in A1.py

It should take as parameters the name of a file containing a forest definition and the list of available tree species and return an instance of the Forest class containing the set of trees and corresponding ages specified in the file. Trees should be identified by matching based on their name.

In some cases, the Forest file may name trees that are not present in the currently loaded Trees file. Whenever this occurs, the program should print that that tree does not exist, and the line should be skipped.

If the file does not exist, the function should print that the file is not found and return None.

You will need to include your class definitions for Tree and Forest from parts 1 and 2, and your load_trees_from_file() function from part 3 in your answer.

Consider the following code fragment:

trees = load_trees_from_file('Trees.txt') forest = load_forest_from_file('Forest.txt', trees) print(forest)

If the file Trees.txt contains the following lines:

Ash,10,150,75,0,0,255,0,30 Oak,12,130,70,0,0,200,0,45 

And the file Forest.txt contains the following lines:

 
Ash,4 Ash,6 Oak,8 Beech,3 Pine,5

The output will be:

 

Tree Beech does not exist! Tree Pine does not exist! Forest contains 3 trees: 4 year old Ash 6 year old Ash 8 year old Oak

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!