-
Notifications
You must be signed in to change notification settings - Fork 0
/
03.py
53 lines (43 loc) · 1.19 KB
/
03.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# A simple class encapsulating the pattern
# functions form the previous questions
__author__ = "Jagadish Kumar P"
__email__ = "[email protected]"
class DrawPattern():
def __init__(self):
self.setRadius(15)
def getRadius(self):
return self.radius
def setRadius(self, radius):
self.radius = radius
def printAnswer(self, pattern):
print pattern
def drawCircle(self):
r = self.getRadius()
diameter = 2*r+(r/2)
drawPattern = ''
for i in range(-((r/2)-2), diameter-1):
for j in range(-((r/2)-2), diameter-1):
xAxis = (i-r)
yAxis = (j-r)
if( (xAxis*xAxis) + (yAxis*yAxis) <= (r*r) ):
drawPattern+='#'
elif( ( (xAxis*xAxis) + (yAxis*yAxis)) >= ( (r*r)*1.5) ):
drawPattern+='#'
else:
drawPattern+='.'
drawPattern+='\n'
self.printAnswer( drawPattern )
return
def drawRect(self):
n = 10
for x in range(n): print("#"*n) if not x%3 else ("#.."* (n/3) + "#")
if __name__ == '__main__':
p = DrawPattern()
print "Rectangle Pattern:"
print "------------------"
p.drawRect()
print "----------------"
print "Circle Pattern:"
print "----------------"
p.drawCircle()