Skip to content

Instantly share code, notes, and snippets.

@themagicalmammal
Created October 16, 2022 07:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themagicalmammal/6881bf82cb6a552c11514cb0f350141e to your computer and use it in GitHub Desktop.
Save themagicalmammal/6881bf82cb6a552c11514cb0f350141e to your computer and use it in GitHub Desktop.
Write a python script to output the below figure on the command prompt. Follow the most creative and efficient way to do this.
#!/usr/bin/python
# -*- coding: utf-8 -*-
def hexagon(width, height, half=0):
i = 0
top = 1
bottom = 1
if half == 1:
top = 0
elif half == -1:
bottom = 0
while i <= height + 1:
if i == 0 and top:
print(' ' * (height//2) + '_' * width)
if i > 0 and i < height//2 + 1 and top:
print(' ' * (height//2 - i) + '/' + ' ' * (width + 2* (i - 1)) + '\\')
if i > height//2 - 1 and i < height - 1 and bottom:
print(' ' * (i - height + height//2) + '\\' + ' ' * (width + 2*(height - i - 1)) + '/')
if i == height - 1 and bottom:
print(' ' * (i - height + height//2) + '\\' + '_'* (width + 2*(height - i - 1)) + '/')
i += 1
def endofline(width, height):
print('+' + '-'*(width + height - 2) + '+' )
def stop(width, height):
print('|' + ' '*((width + height)//2 - 3) + 'STOP' +' '*((width + height)//2 - 3) + '|' )
hexagon(6, 4, -1)
endofline(6,4)
hexagon(6, 4)
hexagon(6, 4, 1)
endofline(6,4)
hexagon(6, 4, -1)
stop(6, 4)
hexagon(6, 4, 1)
@themagicalmammal
Copy link
Author

themagicalmammal commented Oct 16, 2022

  ______
 /      \
/        \
+--------+
  ______
 /      \
/        \
\        /
 \______/
\        /
 \______/
+--------+
  ______
 /      \
/        \
|  STOP  |
\        /
 \______/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment