0% found this document useful (0 votes)
9 views

Hands-On - Python - Class and Static Methods

The document contains three implementations of a Circle class in Python. Each version maintains a count of the number of Circle instances created and provides methods to calculate the area of a circle. The third version introduces a static method to return the value of pi, while the first two versions do not include this feature.

Uploaded by

arif895178
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Hands-On - Python - Class and Static Methods

The document contains three implementations of a Circle class in Python. Each version maintains a count of the number of Circle instances created and provides methods to calculate the area of a circle. The third version introduces a static method to return the value of pi, while the first two versions do not include this feature.

Uploaded by

arif895178
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

############################### 1 ############################

from math import pi,floor


#Add Circle class implementation below
class Circle:
no_of_circles=0
def __init__(self,value):
self.radius=value
Circle.no_of_circles=Circle.no_of_circles+1
def area(self):
area=round(self.radius*self.radius*3.14,2)

b=float(area)
return b

############################### 2 ############################
from math import pi,floor
#Add Circle class implementation below
class Circle:
no_of_circles=0
def __init__(self,value):
self.radius=value
Circle.no_of_circles=Circle.no_of_circles+1
@classmethod
def getCircleCount(cls):
return Circle.no_of_circles
def area(self):
area=round(self.radius*self.radius*3.14,2)

b=float(area)
return b
############################### 3 ############################
class Circle:
no_of_circles=0
def __init__(self,value):
self.radius=value
Circle.no_of_circles=Circle.no_of_circles+1
@staticmethod
def getPi(cls):
return cls
@classmethod
def getCircleCount(cls):
return Circle.no_of_circles
def area(self):
area=round(self.radius*self.radius*Circle.getPi(3.14),2)

b=float(area)
return b

You might also like