+1 vote
in Class 12 by kratos

Write a class CITY in Python with following specification :

  • Code # Numberic value
  • Name # String value
  • Pop # Numberic value for Population
  • KM # Numberic value
  • Density # Numberic value for Population Density

Methods:

  • CalDen ( ) # Method to calculate Density as Pop /KM
  • Record ( ) # Method to allow user to enter values Code, Name, Pop, KM and call CalDen ( ) method
  • See ( ) # Method to display all the date members also display a message “Highly Populated Area” is the Density is more than 12000.

1 Answer

+5 votes
by kratos
 
Best 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

...