-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircle.py
More file actions
38 lines (33 loc) · 964 Bytes
/
Circle.py
File metadata and controls
38 lines (33 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Online Python - IDE, Editor, Compiler, Interpreter
import math
#Default constructor
class Circle:
def __init__(self, name = None):
self.radius = 1
self.diameter = 2
#Construct a Circle with Radius, Diameter and Area
def __init__(self, radius=1):
self.radius = radius
self.diameter = 2*radius
self.area = math.pi*radius**2
#return the Diameter of a circle
def diameter(self, radius):
return 2*radius
#return the Area of a circle
def area (self, radius):
return math.pi*radius**2
#String representation
def __repr__(self):
return f"Circle{self.radius}"
c = Circle(5)
print(c.radius.__repr__())
print(c.diameter.__repr__())
print(c.area.__repr__())
c = Circle ()
print(c.radius.__repr__())
print(c.diameter.__repr__())
print(c.area.__repr__())
if __name__ == None:
print(c.radius.__repr__())
print(c.diameter.__repr__())
print(c.area.__repr__())