Sponsor Area
Concept Of Object Oriented Programming
Write a class CITY in Python with following specifications
Instance Attributes
-Code # Numeric value
-Name # String value
-Pop #Numeric value of population
-KM # Numeric value
-Density #Numeric 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 members also display
a message ”Highly Populated Area”
if the Density is more than 12000
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')
Some More Questions From Concept of Object Oriented Programming Chapter
What will be the output of the following python code considering the following set of inputs?
JAYA
My 3 books
PICK2
2120
Also, explain the try and except used in the code.
Counter=0
while True:
try:
Number=int(raw_input('Give a Number'))
break
except ValueError:
Counter=Counter+2
print('Reenter Number')
print(Counter)
My 3 books
PICK2
2120
Counter=0
while True:
try:
Number=int(raw_input('Give a Number'))
break
except ValueError:
Counter=Counter+2
print('Reenter Number')
print(Counter)Write a class CITY in Python with following specifications
Instance Attributes
-Code # Numeric value
-Name # String value
-Pop #Numeric value of population
-KM # Numeric value
-Density #Numeric 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 members also display
a message ”Highly Populated Area”
if the Density is more than 12000
Instance Attributes
-Name # String value
-Pop #Numeric value of population
-KM # Numeric value
-Density #Numeric value for Population Density
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 members also display
a message ”Highly Populated Area”
if the Density is more than 12000
Sponsor Area
Mock Test Series
Mock Test Series



