1.

Write a class CITY in Python with following specification :Code # Numberic valueName # String valuePop # Numberic value for PopulationKM # Numberic valueDensity # Numberic value for Population DensityMethods:CalDen ( ) # Method to calculate Density as Pop /KMRecord ( ) # Method to allow user to enter values Code, Name, Pop, KM and call CalDen ( ) methodSee ( ) # Method to display all the date members also display a message “Highly Populated Area” is the Density is more than 12000.

Answer»

class CITY:

def _init_ (self):

self. Code = 0

self. Name =” ”

self. Pop = 0

self. KM = 0

self. Density = 0

def CalDen (self):

self. Density = self. Pop/self. KM

def Record (self)

self: Code = input (“Enter Code”)

self.Name=raw_input(“Enter Name”)

self. Pop = input (“Enter population”)

self. KM = input (“Enter KM”)

CalDen (self) // or self.CalDen ( )

def See (self):

print Code, name, Pop, KM, Density

if self. Density > 12000:

print (“Highly Populated Area”)

# OR print (“Highly populated Area”)

Note : Accept self. _Cose to indicate private members



Discussion

No Comment Found