Question: Complete the function load_trees_from_file() specified in A1.py It should take as a parameter the name of a file containing a set of trees and return

Complete the function load_trees_from_file() specified in A1.py

It should take as a parameter the name of a file containing a set of trees and return a list containing instances of the Tree class representing all of the trees listed in the file. If the file does not exist, it should print that the file is not found and return None.

You will need to include your Tree class definition from Question 1 in your answer.

Consider the following code fragment:

trees = load_trees_from_file('Trees.txt') [print(t) for t in trees]

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 

The output will be:

Ash Oak

class Tree:

class Tree: def __init__(self,name,length,color_b,color_l,angle): # defining init method self.name = name self.length = length self.color_b = color_b self.color_l = color_l self.angle = angle def __str__(self): # defining str method return self.name def __repr__(self): # defining repr method return 'Tree("{}", {}, {}, {}, {})'.format(self.name,self.length,self.color_b,self.color_l,self.angle)

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!