Question: Write the python3 code for the following classes, given the classes & descriptions: Here's the code for these classes: https://repl.it/@AnonAnon6/NavybluePrettyConditions Please write the code for

Write the python3 code for the following classes, given the classes & descriptions:

Write the python3 code for the following classes, given the classes &descriptions: Here's the code for these classes: https://repl.it/@AnonAnon6/NavybluePrettyConditions Please write the code

Here's the code for these classes: https://repl.it/@AnonAnon6/NavybluePrettyConditions

Please write the code for the following functions relating to these classes:

1 for the following functions relating to these classes: 1 Note: for create_farm_instances

Note: for create_farm_instances use list comprehension

2 3

use list comprehension 2 3 Left to right page order: for page3: count_meat function: only use one line 4 5 left to right

Left to right page order: for page 3: count_meat function: only use one line

4 5

page 6 & 7 6 7 Classes and Functions for HW02.py Note:See the grading rubric at the end of the document for point

left to right page 6 & 7

6 7

distribution Classes Class Name: Farm Class Attribute: company name (str) Name ofthe company the Farm belongs to. In this case, Orgo. Instance Attributes:

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. Functions Function 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 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:clean_livestock_data Parameters raw_livestock_data (list) A list of lists with uncleaned livestock data Return Type: list Description: Note that we have included the raw livestock data in the template's main function. Each sublist contains the information for one Livestock. This function should manipulate the raw data to meat the requirements of the instance attributes of Livestock 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 Livestock definition above. Keep in mind that utilizations should be set to the bool None if the Livestock has no potential utilization. Do NOT change the order of the sublists and their entries. Return a new list of lists with cleaned data. Function 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 name: create_livestock_instances Parameters livestock_data (list) A list of lists with cleaned livestock data (returned from clean_livestock_data()) Return Type: list Description: This function should take in a list of cleaned livestock data and create a list of Livestock instances using the data. Return a new list with the Livestock 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: buy_new_livestock Parameters: livestock_list (list) A list of Livestock instances livestock_quant (list) A list of integers farm (Farm) The Farm that buys new Livestock Return Type: int Description: This function should model the process of a Farm's attempt to buy new Livestock. st and livestock quant will have the same length since the kth entry in livestock_quant represents the number of kth Livestock instance in livestock_list the Farm attempts to buy. For example, if livestock_quant - [2,3,4) and livestock_list = [Livestocki, Livestock2, Livestock3), it means the Farm attempts to buy 2 of Livestocki, 3 of Livestock2, and 4 of Livestock3. The Farm can only buy livestock that are compatible. On a successful purchase, the num_of_livestock and assets of that Farm should be mutated accordingly (Hint: you will have to use the price_in instance variable of the Livestock instances). Return the number of livestock the Farm ends up buying successfully. You may assume that the Farm's assets will never drop below 0. Function name: 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 workerl. addition (bool) True if workers are being added. False otherwise. Return Type: None Type 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. Function 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 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. 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 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. There is a one-line maximum requirement for this function, if this function is not written in one line, it will result in an 80% deduction for the points allocated to this function. 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. 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. 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, "mule': (4400.2, dairy;leather; meat, wool'), draught') 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: 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: 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. Failure to do so will result in an 80% deduction for the points allocated to this function. 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 Orgo's 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. Function name: livestock_to_shortage Parameters livestock_list (list) A list of Livestock instances dift (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 - [Livestocki, Livestock2, Livestock 3] >>> ditt - (-200, 100, -550) >>> livestock_to_shortage (livestock_list, di EE) dog':-200, "cattle': -550) *** Note that 'dog' and 'cattle are the name attributes corresponding to Livestock and Livestock3 instances. *** 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: 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, if this function is not written in one line you will receive 0 points. 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, if this function is not written in one line you will receive 0 points. 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. Functions Function 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 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:clean_livestock_data Parameters raw_livestock_data (list) A list of lists with uncleaned livestock data Return Type: list Description: Note that we have included the raw livestock data in the template's main function. Each sublist contains the information for one Livestock. This function should manipulate the raw data to meat the requirements of the instance attributes of Livestock 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 Livestock definition above. Keep in mind that utilizations should be set to the bool None if the Livestock has no potential utilization. Do NOT change the order of the sublists and their entries. Return a new list of lists with cleaned data. Function 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 name: create_livestock_instances Parameters livestock_data (list) A list of lists with cleaned livestock data (returned from clean_livestock_data()) Return Type: list Description: This function should take in a list of cleaned livestock data and create a list of Livestock instances using the data. Return a new list with the Livestock 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: buy_new_livestock Parameters: livestock_list (list) A list of Livestock instances livestock_quant (list) A list of integers farm (Farm) The Farm that buys new Livestock Return Type: int Description: This function should model the process of a Farm's attempt to buy new Livestock. st and livestock quant will have the same length since the kth entry in livestock_quant represents the number of kth Livestock instance in livestock_list the Farm attempts to buy. For example, if livestock_quant - [2,3,4) and livestock_list = [Livestocki, Livestock2, Livestock3), it means the Farm attempts to buy 2 of Livestocki, 3 of Livestock2, and 4 of Livestock3. The Farm can only buy livestock that are compatible. On a successful purchase, the num_of_livestock and assets of that Farm should be mutated accordingly (Hint: you will have to use the price_in instance variable of the Livestock instances). Return the number of livestock the Farm ends up buying successfully. You may assume that the Farm's assets will never drop below 0. Function name: 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 workerl. addition (bool) True if workers are being added. False otherwise. Return Type: None Type 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. Function 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 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. 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 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. There is a one-line maximum requirement for this function, if this function is not written in one line, it will result in an 80% deduction for the points allocated to this function. 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. 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. 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, "mule': (4400.2, dairy;leather; meat, wool'), draught') 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: 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: 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. Failure to do so will result in an 80% deduction for the points allocated to this function. 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 Orgo's 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. Function name: livestock_to_shortage Parameters livestock_list (list) A list of Livestock instances dift (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 - [Livestocki, Livestock2, Livestock 3] >>> ditt - (-200, 100, -550) >>> livestock_to_shortage (livestock_list, di EE) dog':-200, "cattle': -550) *** Note that 'dog' and 'cattle are the name attributes corresponding to Livestock and Livestock3 instances. *** 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: 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, if this function is not written in one line you will receive 0 points. 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, if this function is not written in one line you will receive 0 points

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!