Skip to content

Commit e4541de

Browse files
hollow_diamond_alphabets.py
The hollow_diamond_alphabet function prints a hollow diamond pattern using uppercase alphabet characters based on the specified size. The parameter n determines the number of rows in the diamond. The function utilizes spaces for alignment and hollow spaces within the diamond structure, creating a visually appealing output. This addition enhances the repository by providing a visually interesting pattern generator that can be used for educational purposes or as a coding exercise.
1 parent 6740aa9 commit e4541de

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

hollow_diamond_alphabets.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
def hollow_diamond_alphabet(n):
1+
def hollow_diamond_alphabet(n: int) -> None:
22
"""
33
Prints a hollow diamond pattern using alphabet characters.
4-
Parameters:
5-
n (int): The size of the diamond. Determines the number of rows.
6-
Example:
7-
>>> hollow_diamond_alphabet(5)
8-
A
9-
B C
10-
D E
11-
F G
12-
H I
13-
F G
14-
D E
15-
B C
16-
A
4+
5+
Parameters:
6+
n (int): The size of the diamond. Determines the number of rows.
7+
8+
Example:
9+
>>> hollow_diamond_alphabet(5)
10+
A
11+
B C
12+
D E
13+
F G
14+
H I
15+
F G
16+
D E
17+
B C
18+
A
1719
"""
1820
alpha = 64
1921
for i in range(1, n + 1):
@@ -24,6 +26,7 @@ def hollow_diamond_alphabet(n):
2426
else:
2527
print(left_spaces + chr(alpha) + hollow_spaces + chr(alpha + 1))
2628
alpha += 2
29+
2730
alpha -= 2
2831
for i in range(n - 1, 0, -1):
2932
left_spaces = " " * (n - i)
@@ -34,6 +37,5 @@ def hollow_diamond_alphabet(n):
3437
print(left_spaces + chr(alpha - 2) + hollow_spaces + chr(alpha - 1))
3538
alpha -= 2
3639

37-
38-
n = int(input())
40+
n = int(input("Enter the size of the diamond: "))
3941
hollow_diamond_alphabet(n)

0 commit comments

Comments
 (0)