Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribedimage text in transcribed

The code for the above classes is given: https://repl.it/@AnonAnon6/NavybluePrettyConditions

Write the code for the following function:

a)Function name : 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.one-line maximum

b) Function name : count_meat Parameters : livestock_list (list) A list of Livestock instances Return Type : int Description : This function should return the number of livestock in livestock_list that could be potentially used as meat. Note that the utilizations attribute could be the bool None . one line max

c) Function name : livestock_to_occurences Parameters : livestock_list_dup (list) A list of Livestock instances with duplicates (i.e. the name attribute of some Livestock instances might be the same) Return Type : dict Description : This function should return a dictionary mapping the names of the Livestock in livestock_list_dup to their corresponding occurrences in the list. For example, one possibility could be {dog:2, cattle:8, llama:3} , meaning there are 2 dogs, 8 cattles, and 3 llamas in livestock_list_dup

d)Function name : remove_dup Parameters : livestock_list_dup (list) A list of Livestock instances with duplicates (i.e. the name attribute of some Livestock instances might be the same) Return Type : list Description : This function should take in a list of Livestock instances with duplicates and returns a new list with no duplicate Livestock . Only include the first unique instance of Livestock in the list returned.

e) Function name : livestock_objs_to_dict Parameters : livestock_list (list) A list of Livestock instances Return Type : dict Description : This function should return a dictionary representation of the Livestock instances in livestock_list . The keys of the dictionary should be the name attributes of the Livestock instances and the values should be tuples of the price_in attributes and the utilizations attributes. For example, one possibility could be { goat:(1000.0, dairy;leather;meat;wool), mule:(4400.2, draught)} Use dictionary comprehension & formatting shown

f) Function 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.

g)Function name : livestock_to_util Parameters : livestock_list (list) A list of Livestock instances Return Type : dict Description : This function should take in a list of Livestock instances and return a dictionary mapping the names of the Livestock to their number of potential utilizations. If the utilizations attribute is the bool None , the corresponding Livestock name should be mapped to 0. In order to receive full credit for this function you must use a dictionary comprehension and follow the formatting mentioned above.

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

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

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

Students also viewed these Databases questions