B02C-2016 – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-CBSE12A-2016-B02C #PYTHON#6290    siteicon   siteicon  

Problem Statement - B02C-2016

Write a class CITY in Python with following specifications

Instance Attributes
-Ccode     # Numeric value
-CName     # String value
-Pop       # Numeric value for Population
-KM        # Numeric value
-Density   # Numeric value for Population Density
Methods:
-DenCal()  # Method to calculate Density as Pop/KM
-Record()  # Method to allow user to enter values
           Ccode,CName,Pop,KM and call DenCal() method
-View()    # Method to display all the members
           also display a message ”Highly Populated City”
           if the Density is more than 10000

Solution

TC++ #6290

class CITY:
    def __init__(self):
        self.Ccode = 0
        self.CName = ""
        self.Pop = 0
        self.KM =0
        self.Density=0
    def DenCal(self):
        self.Density = self.Pop / self.KM
    def Record(self):
        self.Ccode = input("Enter CCode")
        self.CName = raw_input("Enter CName")
        self.Pop = input("Enter population")
        self.KM = input("Enter KM")
        DenCal(self)   // or self.DenCal()
    def View(self):
        print CCode,CName,Pop, KM, Density
        if self.Density > 10000:
             print("Highly populated city")
             # OR print("Highly populated city")


Share

CSKC| Created: 11-Jan-2019 | Updated: 11-Jan-2019|CBSE12A-2016









Back