(Solved) : Complete Function Loadtreesfromfile Specified A1py Take Parameter Name File Containing Set Q44173128 . . .
Complete the functionload_trees_from_file() specified in A1.py
It should take as aparameter the name of a file containing a set of trees and return alist containing instances of the Tree class representing all of thetrees listed in the file. If the file does not exist, it shouldprint that the file is not found and return None.
You will need toinclude your Tree class definition from Question 1 in youranswer.
Consider the followingcode fragment:
trees = load_trees_from_file(‘Trees.txt’)[print(t) for t in trees]
If the file Trees.txtcontains the following lines:
Ash,10,150,75,0,0,255,0,30Oak,12,130,70,0,0,200,0,45
The output willbe:
AshOak
class Tree:
class Tree:
def __init__(self,name,length,color_b,color_l,angle): # defininginit 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)
Expert Answer
Answer to Complete the function load_trees_from_file() specified in A1.py It should take as a parameter the name of a file contain…
OR