Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago