Skip to content

Instantly share code, notes, and snippets.

@jerinisready
Last active September 22, 2021 08:24
Show Gist options
  • Save jerinisready/cfdc3b00255f6bb3ff08e73a1989a426 to your computer and use it in GitHub Desktop.
Save jerinisready/cfdc3b00255f6bb3ff08e73a1989a426 to your computer and use it in GitHub Desktop.

Print the following Pattern.

            *                   # 1
          0 1 0                 # 3
        0 0 1 0 0               # 5
    $ $ # # $ # # $ $           # 9
* * $ $ # # # # # $ $ * *       #13
    $ $ # # $ # # $ $  
        0 0 1 0 0 
          0 1 0 
            *

Explanation

Load Tutorial On Youtube

__doc__ = """
Print the following Pattern.
* # 1
0 1 0 # 3
0 0 1 0 0 # 5
$ $ # # $ # # $ $ # 9
* * $ $ # # # # # $ $ * * #13
$ $ # # $ # # $ $
0 0 1 0 0
0 1 0
*
"""
__author__ = "@jerinisready"
def main():
_center = 7 # (13 + 1) / 2
for line in (1, 3, 5, 9, 13, 9, 5, 3, 1):
# Printing No of Spaces
num_of_spaces = _center - ((line+1) // 2)
print(' ' * num_of_spaces, end='')
# Printing Character
middle_position = (line + 1) / 2
for char_index in range(1, line+1):
printing_character = ''
if line < 2:
printing_character = '*'
elif line < 6:
if middle_position == char_index:
printing_character = '1'
else:
printing_character = '0'
elif line < 10:
if char_index == middle_position:
printing_character = '$'
elif abs(char_index - middle_position) <= 2:
printing_character = '#'
else:
printing_character = '$'
else:
if abs(char_index - middle_position) <= 2:
printing_character = '#'
elif abs(char_index - middle_position) <= 4:
printing_character = '$'
else:
printing_character = '*'
print(f'{printing_character} ', end="")
print()
if __name__ == "__main__":
"Run Main Program"
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment