Skip to content

Commit 2e1bbab

Browse files
authored
python MCA 101 DU
1 parent fa41d21 commit 2e1bbab

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

RecursivePlotSquare.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import matplotlib.pyplot as plt
2+
def square(x,y,size,temp):
3+
'''
4+
Objective: To plot a square
5+
Input Parameters: x, y - lists of x coordinates and y
6+
coordinates respectively
7+
temp- temprorly store axis of square
8+
Return Value: a square
9+
'''
10+
#Approach- Recursive
11+
if(size>0):
12+
13+
x = [temp, size, size, temp, temp]
14+
y = [temp, temp, size, size, temp]
15+
plt.plot(x, y, 'ro--')
16+
return square(x,y,size-1,temp+1)
17+
def main():
18+
'''
19+
Objective: To plot a square based on user input
20+
Input Parameter: x, y - lists of x coordinates and y
21+
coordinates respectively
22+
Return Value: None
23+
'''
24+
#Approach- Call Function square()
25+
size = int(input('Enter size of the square: '))
26+
x = [0, size, size,0,0]
27+
y = [0,0, size, size,0]
28+
temp=-1
29+
square(x, y,size,temp)
30+
plt.title('Square')
31+
plt.axis([min(x)-1, max(x)+1, min(y)-1, max(y)+1])
32+
plt.grid()
33+
plt.show()
34+
if __name__ == '__main__':
35+
main()

0 commit comments

Comments
 (0)