Answered step by step
Verified Expert Solution
Link Copied!

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 : 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 name 2 : sort_farms_num_of_liv
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 name 3 : 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.
Function name 4 : shortage_or_surplus
Parameters :
demand_list (list) A list of integers representing demands
supply_list (list) A list of integers representing supplies
Return Type : list
Description :
This function should take in a list representing customers demands of livestock and a
list representing Orgos supplies of livestock and calculate the shortage or surplus of the
livestock. Shortages should be represented as a negative number and surplus should
be represented as a positive number. Essentially, you are calculating the difference
between these two lists. You may assume the demand_list and supply_list will
always have the same length.
Example Case:
>>> demand_list = [300, 200, 900]
>>> supply_list = [600, 850, 100]
>>> shortage_or_surplus(demand_list, supply_list)
[300, 650, -800]
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.

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

More Books

Students also viewed these Databases questions