Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

given the class livestock write the following 5 functions using python: raw_livestock_data = [ # name, price_in, utilizations ['Dog', '200.0', 'Draught,Hunting,Herding,Searching,Guarding.'], ['Goat', '1000.0', 'Dairy,Meat,Wool,Leather.'], ['Python',

given the class livestock

image text in transcribed

write the following 5 functions using python:

image text in transcribed

image text in transcribed

image text in transcribed

raw_livestock_data = [ # name, price_in, utilizations ['Dog', '200.0', 'Draught,Hunting,Herding,Searching,Guarding.'], ['Goat', '1000.0', 'Dairy,Meat,Wool,Leather.'], ['Python', '10000.3', ''], ['Cattle', '2000.75', 'Meat,Dairy,Leather,Draught.'], ['Donkey', '3400.01', 'Draught,Meat,Dairy.'], ['Pig', '900.5', 'Meat,Leather.'], ['Llama', '5000.66', 'Draught,Meat,Wool.'], ['Deer', '920.32', 'Meat,Leather.'], ['Sheep', '1300.12', 'Wool,Dairy,Leather,Meat.'], ['Rabbit', '100.0', 'Meat,Fur.'], ['Camel', '1800.9', 'Meat,Dairy,Mount.'], ['Reindeer', '4000.55', 'Meat,Leather,Dairy,Draught.'], ['Mule','4400.2', 'Draught.'], ]

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 other.utilizations is None: return False else: return self.utilizations.count(';')

def clean_livestock_data(raw_livestock_data): livestock_data = [] for y in raw_livestock_data: charac = [] charac.append(str(y[0].lower())) charac.append(float(y[1])) if len(y[2]) == 0: charac.append(None) else: new_y = (y[2].strip(".")).split(",") charac.append((";".join(sorted(new_y))).lower()) livestock_data.append(charac) return livestock_data

def create_livestock_instances(livestock_data): return [Livestock(i[0],i[1],i[2]) for i in livestock_data]

please solve the remaining functions

class Livestock: #initializing all the atributes def __init_(self, name,price_in,utilizations): self.name,self.price_in,self.utilizations = name,float(price_in), utilizations #making class sortable by implementing It method using in internal sort in python def_lt__(self,other): #if current instance has no utilization if self.utilizations is None: return True #if other instance has no utilization elif other.utilizations is None: return False #check which object has more utilization else: return self.utilizations.count(';')

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

Students also viewed these Databases questions