Answered step by step
Verified Expert Solution
Question
1 Approved Answer
class Farm: company_name = Orgo def __init__(self,name,owner,country,size,num_of_livestock,num_of_workers,assets,compatible_livestock): self.name = name self.owner = owner self.country = country self.size = size self.num_of_livestock = num_of_livestock self.num_of_workers = num_of_workers
class Farm:
company_name = "Orgo"
def __init__(self,name,owner,country,size,num_of_livestock,num_of_workers,assets,compatible_livestock):
self.name = name
self.owner = owner
self.country = 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
def __gt__(self,other):
if(self.assets > other.assets):
return True
return False
def __eq__(self,other):
if(self.name == other.name and self.owner == other.owner):
return True
else:
return False
def __repr__(self):
return self.name
raw_farm_data = [
# name, owner, country, size, number of livestock, number of workers, assets, compatible livestock
['2316 TA Family Farm', 'Melinda McDaniel', 'Atlanta, GA, USA', '1600', '3000', '7', '6000000', {'Dog', 'Goat', 'Pig', 'Python', 'Cattle', 'Donkey'}],
['Schrute Beets Farm', 'Dwight Schrute', 'Scranton, PA, USA', '300', '860', '4', '55000', {'Pig', 'Llama', 'Cattle', 'Dog', 'Deer'}],
['Dairy Farm of Lady Mary', 'Mary Crawley', 'Hampshire, UK', '2000', '749', '30', '1100000', {'Goat', 'Donkey', 'Cattle', 'Sheep', 'Horse'}],
["Gollum's Furry Things Farm", 'Gollum', 'Brisbane, Queensland, Australia', '550', '90', '23', '150000', {'Goat', 'Sheep', 'Dog', 'Llama', 'Rabbit', 'Camel'}],
['Santa Claus Independent Farm', 'Santa Claus', 'Lapland, Finland', '760', '60', '1', '14400', {'Reindeer', 'Llama'}],
['Scott Family Farm', 'Michael Scott', 'Canada', '300', '50', '10', '230000', {'Horse', 'Mule', 'Donkey', 'Pig'}],
['Organic Veggie Farm', 'Jim Halpert', 'New Mexico, USA', '230', '0', '20', '88000', {}]
]
given the above class and the raw data write the following fuctions using python:
Function name 1: 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 templates 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 if 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 name 2 : 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 name 3: mutate_workers
Parameters : farm ( Farm ) The Farm that has a change of workers num_changed (int) Change in the number of workers. Always positive. Equivalent to |delta worker|. addition (bool) True if workers are being added. False otherwise.
Return Type : NoneType
Description : This function should model the process of a Farm hiring new workers or firing existing workers. The num_of_workers on the Farm should be mutated accordingly. Keep in mind that the num_changed parameter is always positive. addition is True if a Farm is hiring new workers and False if it is firing existing workers.
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