Created
October 16, 2022 07:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Author
themagicalmammal
commented
Oct 16, 2022
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment