repl.it
@charles2588/

PrintSpirals

Python

No description

fork
loading
Files
  • main.py
main.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
def printsprial(m,n):
	arr=[]
	count=0
	for i in range(m):
		arr.append([])
		for j in range(n):
			count+=1
			arr[i].append(count)
	
	print(arr)
	topwall=0
	rightwall=n-1
	leftwall=0
	bottomwall=m-1
	count=0
	i=1
	while count<m*n:
			if i==1:
				j=leftwall
				while j<=rightwall:
					print(arr[topwall][j])
					count+=1
					j+=1
				topwall+=1
				i=2
			if i==2:
				j=topwall
				while j<=bottomwall:
					print(arr[j][rightwall])
					count+=1
					j+=1
				rightwall-=1
				i=3
			if i==3:
				j=rightwall
				while j>=leftwall:
					print(arr[bottomwall][j])
					count+=1
					j-=1
				bottomwall-=1
				i=4
			if i==4:
				j=bottomwall
				while j>=topwall:
					print(arr[j][leftwall])
					count+=1
					j-=1
				leftwall+=1
				i=1
	
printsprial(4,5)
		 
?