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 4 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
37 changes: 37 additions & 0 deletions hollow_diamond_alphabets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def hollow_diamond_alphabet(n):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occurred while parsing the file: hollow_diamond_alphabets.py

Traceback (most recent call last):
  File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
    reports = lint_file(
              ^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:1.
tokenizer error: no matching outer block for dedent

def hollow_diamond_alphabet(n):
^

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occurred while parsing the file: hollow_diamond_alphabets.py

Traceback (most recent call last):
  File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
    reports = lint_file(
              ^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:1.
tokenizer error: no matching outer block for dedent

def hollow_diamond_alphabet(n):
^

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occurred while parsing the file: hollow_diamond_alphabets.py

Traceback (most recent call last):
  File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
    reports = lint_file(
              ^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:1.
tokenizer error: no matching outer block for dedent

def hollow_diamond_alphabet(n):
^

'''
Prints a hollow diamond pattern using alphabet characters.
Parameters:
n (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,n+1):
left_spaces=" "*(n-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(n-1,0,-1):
left_spaces=" "*(n-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
n=int(input())
hollow_diamond_alphabet(n)