Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create hollow_diamond_alphabets.py #12106

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions hollow_diamond_alphabets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def hollow_diamond_alphabet(diamond_size: int) -> None:
"""
Prints a hollow diamond pattern using alphabet characters.

Parameters:
diamond_size (int): The size of the diamond. Determines the number of rows.

Example:
>>> hollow_diamond_alphabet(5)
A
B C
D E
F G
H I
F G
D E
B C
A
"""
alpha = 64
for i in range(1, diamond_size + 1):
left_spaces = " " * (diamond_size - i)
hollow_spaces = " " * (((i - 1) * 2) - 1)
if i == 1:
print(left_spaces + chr(alpha + 1))
else:
print(left_spaces + chr(alpha) + hollow_spaces + chr(alpha + 1))
alpha += 2

alpha -= 2
for i in range(diamond_size - 1, 0, -1):
left_spaces = " " * (diamond_size - i)
hollow_spaces = " " * (((i - 1) * 2) - 1)
if i == 1:
print(left_spaces + chr(alpha - 1))
else:
print(left_spaces + chr(alpha - 2) + hollow_spaces + chr(alpha - 1))
alpha -= 2


# Example usage
diamond_size = int(input("Enter the diamond size: "))
hollow_diamond_alphabet(diamond_size)
Loading