Question
Write the python3 code for the following classes, given the classes & descriptions: The code for the above classes is given: https://repl.it/@AnonAnon6/NavybluePrettyConditions Write the code
Write the python3 code for the following classes, given the classes & descriptions:
The code for the above classes is given: https://repl.it/@AnonAnon6/NavybluePrettyConditions
Write the code for the following function:
a) Function name : 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
b)Function name : livestock_to_shortage Parameters : livestock_list (list) A list of Livestock instances diff (list) A list of positiveegative integers Return Type : dict Description : This function should return a dictionary mapping the names of the Livestock within livestock_list to the corresponding integer in diff only if the corresponding integer is negative . If the corresponding integer from diff is positive , you should not include the Livestock instance or the positive integer in your dictionary. Return an empty dictionary if all of the Livestock in livestock_list has a corresponding positive integer. You may assume livestock_list and diff will always have the same length, since each element in diff corresponds to a Livestock instance.
Example Case: >>> livestock_list = [Livestock1, Livestock2, Livestock3]
>>> diff = [-200, 100, -550]
>>> livestock_to_shortage(livestock_list, diff) {dog:-200, cattle: -550}
*** Note that dog and cattle are the name attributes corresponding to Livestock1 and Livestock3 instances. *** In order to receive full credit for this function you must use a dictionary comprehension and follow the formatting mentioned above
c) Function name : livestock_shallow_copy Parameters : livestock_list (list) A list of Livestock instances.
Return Type : list Description : This function should take in a list of Livestock instances and return a shallow copy of that list. There is a one-line maximum requirement for this function
d) Function name : livestock_deep_copy Parameters : livestock_list (list) A list of Livestock instances Return Type : list Description : This function should take in a list of Livestock instances and return a deep copy of that list. There is a one-line maximum requirement for this function
Classes and Functions for HW02.py Note: See the grading rubric at the end of the document for point distribution Classes Class Name: Farm Class Attribute: company name (str) Name of the company the Farm belongs to. In this case, Orgo. Instance Attributes: name Name of the Farm owner (str) Name of the Farm owner country Country the Farm is in size Size of the Farm in acres Number of Livestock the Farm owns num_of_livestock num_of_workers Number of workers the Farm employs assets Amount of assets the Farm owns (int) (str) compatible_livestock Types of Livestock the Farm is able to keep. More on the format below. Note: The format of compatible_livestock will satisfy the following rules: Must be all lower case Types of Livestock should be separated by semicolons Types of Livestock should be in ascending alphabetical order Replace with the bool None if the Farm has no compatible livestock Example: "deer;dogdonkey,mule:pig" Description: Write a class called Farm with the above attributes. Write the appropriate methods to accomplish the following tasks: Method #1 Initializes the attributes in the sequence listed above. Method #2 Makes the instances of the Farm class sortable based on assets. Method #3 Checks if two instances of the Farm class are equal to each other. If a Farm has the same name and owner as another, then the two instances are equal to each other. Method #4 When a Farm instance is called in the Python shell or printed, the name of the Farm should be returned. Class Name: Livestock Instance Attributes: name (str) Name of the Livestock. Should be all lowercase. price_in (float) Price to buy the Livestock utilizations (str) Things the Livestock could be used for. More on the format below. Note: The format of utilizations will satisfy the following rules: . Must be all lower case Utilizations should be separated by semicolons Utilizations should be in ascending alphabetical order Replace with the bool None if the Livestock has no potential utilization Example: "dairy;fur;meat,wool Description: Write a class called Livestock with the above attributes. Write the appropriate methods to accomplish the following tasks: Method #1 Initializes the attributes in the sequence listed above. Method #2 Makes the instances of the Livestock class sortable based on the number of potential utilizations. Method #3 Checks if two instances of the Livestock class are equal to each other. If a Livestock has the same name as another, then the two instances are equal to each other. Method #4 When a Livestock instance is called in the Python shell or printed, the following statement should be returned: "name, price_in" Example: "dog, 200.0" Make sure your output matches the format above exactly. Classes and Functions for HW02.py Note: See the grading rubric at the end of the document for point distribution Classes Class Name: Farm Class Attribute: company name (str) Name of the company the Farm belongs to. In this case, Orgo. Instance Attributes: name Name of the Farm owner (str) Name of the Farm owner country Country the Farm is in size Size of the Farm in acres Number of Livestock the Farm owns num_of_livestock num_of_workers Number of workers the Farm employs assets Amount of assets the Farm owns (int) (str) compatible_livestock Types of Livestock the Farm is able to keep. More on the format below. Note: The format of compatible_livestock will satisfy the following rules: Must be all lower case Types of Livestock should be separated by semicolons Types of Livestock should be in ascending alphabetical order Replace with the bool None if the Farm has no compatible livestock Example: "deer;dogdonkey,mule:pig" Description: Write a class called Farm with the above attributes. Write the appropriate methods to accomplish the following tasks: Method #1 Initializes the attributes in the sequence listed above. Method #2 Makes the instances of the Farm class sortable based on assets. Method #3 Checks if two instances of the Farm class are equal to each other. If a Farm has the same name and owner as another, then the two instances are equal to each other. Method #4 When a Farm instance is called in the Python shell or printed, the name of the Farm should be returned. Class Name: Livestock Instance Attributes: name (str) Name of the Livestock. Should be all lowercase. price_in (float) Price to buy the Livestock utilizations (str) Things the Livestock could be used for. More on the format below. Note: The format of utilizations will satisfy the following rules: . Must be all lower case Utilizations should be separated by semicolons Utilizations should be in ascending alphabetical order Replace with the bool None if the Livestock has no potential utilization Example: "dairy;fur;meat,wool Description: Write a class called Livestock with the above attributes. Write the appropriate methods to accomplish the following tasks: Method #1 Initializes the attributes in the sequence listed above. Method #2 Makes the instances of the Livestock class sortable based on the number of potential utilizations. Method #3 Checks if two instances of the Livestock class are equal to each other. If a Livestock has the same name as another, then the two instances are equal to each other. Method #4 When a Livestock instance is called in the Python shell or printed, the following statement should be returned: "name, price_in" Example: "dog, 200.0" Make sure your output matches the format above exactlyStep 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