Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1f307e8

Browse files
authoredOct 16, 2024··
Update 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.
1 parent 6c92b8d commit 1f307e8

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed
 

‎hollow_diamond_alphabets.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
def hollow_diamond_alphabet(n: int) -> None:
1+
def hollow_diamond_alphabet(diamond_size: int):
22
"""
33
Prints a hollow diamond pattern using alphabet characters.
44
55
Parameters:
6-
n (int): The size of the diamond. Determines the number of rows.
6+
diamond_size (int): The size of the diamond. Determines the number of rows.
77
88
Example:
99
>>> 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
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
1919
"""
2020
alpha = 64
21-
for i in range(1, n + 1):
22-
left_spaces = " " * (n - i)
21+
for i in range(1, diamond_size + 1):
22+
left_spaces = " " * (diamond_size - i)
2323
hollow_spaces = " " * (((i - 1) * 2) - 1)
2424
if i == 1:
2525
print(left_spaces + chr(alpha + 1))
@@ -28,15 +28,15 @@ def hollow_diamond_alphabet(n: int) -> None:
2828
alpha += 2
2929

3030
alpha -= 2
31-
for i in range(n - 1, 0, -1):
32-
left_spaces = " " * (n - i)
31+
for i in range(diamond_size - 1, 0, -1):
32+
left_spaces = " " * (diamond_size - i)
3333
hollow_spaces = " " * (((i - 1) * 2) - 1)
3434
if i == 1:
3535
print(left_spaces + chr(alpha - 1))
3636
else:
3737
print(left_spaces + chr(alpha - 2) + hollow_spaces + chr(alpha - 1))
3838
alpha -= 2
3939

40-
41-
n = int(input("Enter the size of the diamond: "))
42-
hollow_diamond_alphabet(n)
40+
# Example usage
41+
diamond_size = int(input("Enter the diamond size: "))
42+
hollow_diamond_alphabet(diamond_size)

0 commit comments

Comments
 (0)
Please sign in to comment.