forked from harshilp24/Hacktoberfest_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hollow_Diamond_Pattern.py
94 lines (73 loc) · 1.42 KB
/
Hollow_Diamond_Pattern.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Print hollow diamond pattern using '*'. See examples for more details.
Input Format
First line of input contains T - number of test cases. Its followed by T lines, each line contains a single odd integer N - the size of the diamond.
Constraints
1 <= T <= 100
3 <= N <= 201
Output Format
For each test case, print the test case number as shown, followed by the diamond pattern, separated by newline.
Sample Input 0
4
3
7
5
15
Sample Output 0
Case #1:
*
* *
*
Case #2:
*
* *
* *
* *
* *
* *
*
Case #3:
*
* *
* *
* *
*
Case #4:
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
"""
test_cases = int(input())
def place_stars(pattern, positions):
for i in positions:
pattern[i] = '*'
return ''.join(pattern)
def star_positions(lines):
stars = [[lines]]
return stars + [[lines-i, lines+i] for i in range(1, lines+1)]
def make_pattern(size):
pattern = [' ' * (2*(size+1)-1) for i in range(size+1)]
stars = star_positions(size)
line = 0
for star in stars:
pattern[line] = place_stars(list(pattern[line]), star)
print(pattern[line])
line += 1
for i in pattern[:-1][::-1]:
print(i)
for i in range(test_cases):
n = int(input())
print('Case #' + str(i + 1) + ':')
make_pattern( n // 2)