1.

Define a class SUPPLY in Python with the following description: Private Members Code of type int FoodName of type string FoodType of type string Sticker of type string A member function GetType() to assign the following values for Food Type as per the given Sticker A function Foodln() to allow user to enter values for Code, EoodName, Sticker and call function GetType() to assign respective FoodType.StickerFood TypeGREENVegetarianYELLOWContains EggREDNon-VegetarianPUBLIC MEMBERSA function FoodOut() to allow user to view the contents of all the data members.

Answer»

class SUPPLY:

• constructor to create an object

def init (self) :

#constructor

self.FoodCode=()

self.FoodName=‘ ’

self.FoodType=‘ ’

self.Sticker=‘ ’

def Foodln(self):

self.FoodCode=input(“Enter Food Code”)

self.FoodName=raw_input(“Enter Food Name”)

self.Sticker=raw_input(“Enter Sticker Colour”)

def GetType(self):

if self.Sticker==‘GREEN’:

self.FoodType = ‘Vegetarian’

elif self.Sticker==’YELLOW’:

self.FoodType = ‘Contains Egg’

elif self.Sticker==‘RED’:

self.FoodType = ‘Non-Vegetarian’ else:

self.FoodType = ‘Not Known’

def FoodOut(self):

print “FoodCode’’,self.FoodCode

print “FoodName”,self.FoodName

print “FoodType”,self.FoodType

print “Sticker”,self.Sticker

S = SUPPLY()

S.FoodIn()

S.GetTÿpe()

S.FoodOut()



Discussion

No Comment Found