QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A CBSE12D-2017-B02C #6409

Question:

Define a class RING in Python with following specifications

Instance Attributes
- RingID  # Numeric value with a default value 101
- Radius  # Numeric value with a default value 10
- Area    # Numeric value
Methods:
- AreaCal()  # Method to calculate Area as
             # 3.14*Radius*Radius
- NewRing()  # Method to allow user to enter values of
             # RingID and Radius. It should also
             # Call AreaCal Method
- ViewRing() # Method to display all the Attributes

Answer:

class RING: # OR class RING( ): OR class RING(Object):
    def __init__(self):
        self.RingID=101
        self.Radius=10
        self.Area=0
    def AreaCal(self):
        self.Area=3.14*self.Radius*self.Radius
    def NewRing(self):
        self.RingID=input("Enter RingID")
        self.Radius=input("Enter radius")
        self.AreaCal() # OR AreaCal(self)
    def ViewRing(self):
        print self.RingID
        print self.Radius
        print self.Area