python code :
Problem 1 : define a function sort_farms_num_of_liv
def sort_farms_assets(raw_farm_data):
#using sorted function and lambda function as a combination
# sorted function takes 3 inputs list,reverse and key where last 2 are optional
return sorted(raw_farm_data,reverse=True,key=lambda
raw_farm_data:int(raw_farm_data[6]))
sort_farms_assets(raw_farm_data)
Problem 2 :define A function sort_farms_num_of_liv
def sort_farms_num_of_liv(raw_farm_data):
#using sorted function and lambda function as a combination
# sorted function takes 3 inputs list,reverse and key where last 2 are optional
return sorted(raw_farm_data,reverse=True,key=lambda
raw_farm_data:int(raw_farm_data[4]))
sort_farms_num_of_liv(raw_farm_data)
Problem 3 :define A function farm_to_density
def farm_to_density(raw_farm_data):
#creating a empty list to collect farm name and its
density
farm_density_dictionary={}
for i in raw_farm_data:
density=int(i[4])/int(i[3])
farm_density_dictionary[i[0]]=density
return farm_density_dictionary
farm_to_density(raw_farm_data)
Problem 4 :define a function shortage_or_surplus
def shortage_or_surplus(demand_list,supply_list):
#return a list comprehension assuming both input list has equal
length and comprises of int value
return [supply_list[i]-demand_list[i] for i in
range(len(demand_list))]
demand_list = [300, 200, 900]
supply_list = [600, 850, 100]
shortage_or_surplus(demand_list,supply_list)
sample screenshot
class Livestock: def __init__(self,name,price_in,utilizations): self.name,self.price_in,self.utilizations = name,float(price_in),utilizations def __lt__(self,other): if self.utilizations is None: return True elif...
class BinaryTree: def __init__(self, data, left=None, right=None): self.__data = data self.__left = left self.__right = right def insert_left(self, new_data): if self.__left == None: self.__left = BinaryTree(new_data) else: t = BinaryTree(new_data, left=self.__left) self.__left = t def insert_right(self, new_data): if self.__right == None: self.__right = BinaryTree(new_data) else: t = BinaryTree(new_data, right=self.__right) self.__right = t def get_left(self): return self.__left def get_right(self): return self.__right def set_data(self, data): self.__data = data def get_data(self): return self.__data def set_left(self, left): self.__left = left def set_right(self, right): self.__right...
Previous code: class BinarySearchTree: def __init__(self, data): self.data = data self.left = None self.right = None def search(self, find_data): if self.data == find_data: return self elif find_data < self.data and self.left != None: return self.left.search(find_data) elif find_data > self.data and self.right != None: return self.right.search(find_data) else: return None def get_left(self): return self.left def get_right(self): return self.right def set_left(self, tree): self.left = tree def set_right(self, tree): self.right = tree def set_data(self, data): self.data = data def get_data(self): return self.data def traverse(root,order):...
class WorkoutClass: """A workout class that can be offered at a gym. === Private Attributes === _name: The name of this WorkoutClass. _required_certificates: The certificates that an instructor must hold to teach this WorkoutClass. """ _name: str _required_certificates: List[str] def __init__(self, name: str, required_certificates: List[str]) -> None: """Initialize a new WorkoutClass called <name> and with the <required_certificates>. >>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class.get_name() 'Kickboxing' """ def get_name(self) -> str: """Return the name of this WorkoutClass. >>> workout_class =...
PYHTON Preliminaries For this assignment you will be working with the following classes, which are available in the file homework5-classes.py: class Pharmacy: def _init_(self, inventory, unit_prices) self.inventory - inventory self.unit_prices-unit_prices class Prescription: definit_(self, patient, drug_name, quantity): self.patient- patient self.drug_namedrug_name self.quantity - quantity You will be asked to write several functions that work with the Prescription and Pharmacy classes. To complete this assignment you may write any helper functions you like inside your homework5.py file. Pharmacy class attributes: * inventory: A...