Answered step by step
Verified Expert Solution
Question
1 Approved Answer
given the class farm: write those 5 functions using python: the functions descriptions are given what info are you missing? please my questions are complete.
given the class farm:
write those 5 functions using python:
the functions descriptions are given
what info are you missing? please my questions are complete.
*untitled class Farm: company_name = "Orgo" #constructor to initialize all fields listed in question. def __init__(self, name, owner, country, size, num_of_livestock, num_of_workers, assets, compatible_livestock): self.name = name self.owner Owner self.counry = country self.size - size self.num_of_livestock = num_of_livestock self.num_of_workers = num_of_workers self.assets = assets self.compatible_livestock = compatible_livestock #overide greater than operator to return True #if self.assets is > other.assets if not False #which makes Farm class instances to be Sortable. def --gt__(self,other): if(self.assets > other.assets): return True return false #check two instances self other are equal to each other. #by overiding - operator was provided in question return True only if name is equal and owners are not equal #if not return False def _.eq..(self,other): (self.name other name and self.owner I - other owner): return True else: return false #returning the name of the Farm instance #whenever it is called in console or print statement. #to do it we have to override - str. method. def -.str__(self): return self.name #metohd to sort Farm instances array. def sort farm_objects(array): #get length of array total_objs - len(array) Function 1 name : clean farm data Parameters : raw. farm data (list) A list of lists with uncleaned farm data Return Type : list Description : Note that we have included the raw farm data in the template's main function. Each sublist contains the information for one Farm. This function should manipulate the raw data to meat the requirements of the instance attributes of Farm defined above. In other words, for each sublist, you need to make sure that each entry is of the correct type, contains the desired information, and is in the right format. Refer to the Farm definition above. Keep in mind that compatible livestock should be set to the bool None of the Farm has no compatible livestock. Do NOT change the order of the sublists and their entries. Return a new list of lists with cleaned data. Function 2 name: create farm instances Parameters : farm data (list) A list of lists with cleaned farm data (returned from clean farm data ) Return Type: list Description : This function should take in a list of cleaned farm data and create a list of Farm instances using the data. Return a new list with the Farm instances. Create the instances in the order of the sublists. In order to receive full credit for this function you must use a list comprehension and follow the formatting mentioned above. Failure to do so will result in an 80% deduction for the points allocated to this function. Function 3 name : sort farms.assets Parameters : farms list (list) A list of Farm instances to be sorted Return Type: list Description : This function should return a sorted list of Farm instances based on the assets in descending order. There is a one-line maximum requirement for this function, if this function is not written in one line you will receive 0 points. Function 4 name : sort farms.num of liy Parameters : farms list (list) A list of Farm instances to be sorted Return Type : list Description : This function should return a sorted list of Farm instances based on the number of livestock in descending order. There is a one-line maximum requirement for this function, if this function is not written in one line you will receive 0 points. Function 5 name : farm to density Parameters : farms list (list) A list of Farm instances Return Type : dict Description : This function should take in a list of Farm instances and return a dictionary mapping the names of the Farm's to their livestock densities, which is calculated as the number of livestock on the farm divided by its size. In order to receive full credit for this function you must use a dictionary comprehension and follow the formatting mentioned above. Failure to do so will result in an 80% deduction for the points allocated to this function. *untitled class Farm: company_name = "Orgo" #constructor to initialize all fields listed in question. def __init__(self, name, owner, country, size, num_of_livestock, num_of_workers, assets, compatible_livestock): self.name = name self.owner Owner self.counry = country self.size - size self.num_of_livestock = num_of_livestock self.num_of_workers = num_of_workers self.assets = assets self.compatible_livestock = compatible_livestock #overide greater than operator to return True #if self.assets is > other.assets if not False #which makes Farm class instances to be Sortable. def --gt__(self,other): if(self.assets > other.assets): return True return false #check two instances self other are equal to each other. #by overiding - operator was provided in question return True only if name is equal and owners are not equal #if not return False def _.eq..(self,other): (self.name other name and self.owner I - other owner): return True else: return false #returning the name of the Farm instance #whenever it is called in console or print statement. #to do it we have to override - str. method. def -.str__(self): return self.name #metohd to sort Farm instances array. def sort farm_objects(array): #get length of array total_objs - len(array) Function 1 name : clean farm data Parameters : raw. farm data (list) A list of lists with uncleaned farm data Return Type : list Description : Note that we have included the raw farm data in the template's main function. Each sublist contains the information for one Farm. This function should manipulate the raw data to meat the requirements of the instance attributes of Farm defined above. In other words, for each sublist, you need to make sure that each entry is of the correct type, contains the desired information, and is in the right format. Refer to the Farm definition above. Keep in mind that compatible livestock should be set to the bool None of the Farm has no compatible livestock. Do NOT change the order of the sublists and their entries. Return a new list of lists with cleaned data. Function 2 name: create farm instances Parameters : farm data (list) A list of lists with cleaned farm data (returned from clean farm data ) Return Type: list Description : This function should take in a list of cleaned farm data and create a list of Farm instances using the data. Return a new list with the Farm instances. Create the instances in the order of the sublists. In order to receive full credit for this function you must use a list comprehension and follow the formatting mentioned above. Failure to do so will result in an 80% deduction for the points allocated to this function. Function 3 name : sort farms.assets Parameters : farms list (list) A list of Farm instances to be sorted Return Type: list Description : This function should return a sorted list of Farm instances based on the assets in descending order. There is a one-line maximum requirement for this function, if this function is not written in one line you will receive 0 points. Function 4 name : sort farms.num of liy Parameters : farms list (list) A list of Farm instances to be sorted Return Type : list Description : This function should return a sorted list of Farm instances based on the number of livestock in descending order. There is a one-line maximum requirement for this function, if this function is not written in one line you will receive 0 points. Function 5 name : farm to density Parameters : farms list (list) A list of Farm instances Return Type : dict Description : This function should take in a list of Farm instances and return a dictionary mapping the names of the Farm's to their livestock densities, which is calculated as the number of livestock on the farm divided by its size. In order to receive full credit for this function you must use a dictionary comprehension and follow the formatting mentioned above. Failure to do so will result in an 80% deduction for the points allocated to this function Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started