Last active
July 30, 2019 15:26
-
-
Save therealprocyon/3e34788db070164cdfb3a5cc30eb9ca9 to your computer and use it in GitHub Desktop.
Some board drawing function in text
This file contains 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/env python3 | |
def draw_board(width, length): | |
for x in range(length): | |
print(" ---" * width + " ") | |
print("| " * width + "|") | |
print(" ---" * width + " ") | |
def validate_size(width): | |
try: | |
width = int(width) | |
return width | |
except ValueError as e: | |
if not width: | |
print("Boardsize can't be empty.") | |
exit(1) | |
else: | |
print("Boardsize is not a valid integer.\n\n" + | |
"Run the program again to solve this\n\n") | |
exit(1) | |
def main(): | |
width = input("Enter a single number for the boardsize: ") | |
width = validate_size(width) | |
length = width | |
draw_board(width, length) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment