Created
October 24, 2019 07:47
-
-
Save tpoerschke/c3e419c4f96a578d8dd21010998aac9f to your computer and use it in GitHub Desktop.
Cowsay in Python
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
import sys | |
cow = """ | |
\\ | |
\ ( ) | |
(oo) | |
)\.-----/(O O) | |
# ; / u | |
( . |} ) | |
|/ `.;|/; | |
" " " | |
""" | |
if len(sys.argv) <= 1: | |
print("Enter message...") | |
exit() | |
line = "" | |
lines = [] | |
wordCount = 0 | |
for word in sys.argv[1:]: | |
line += word + " " | |
wordCount += 1 | |
if(wordCount == 10): | |
lines.append(line) | |
line = "" | |
wordCount = 0 | |
if line != "": | |
lines.append(line) | |
maxLength = len(lines[0]) | |
for line in lines: | |
if len(line) > maxLength: | |
maxLength = len(line) | |
print(" " + "_" * (maxLength + 2)) | |
if len(lines) == 1: | |
print("< " + lines[0].ljust(maxLength) + " >") | |
else: | |
for i in range(len(lines)): | |
if i == 0: | |
print("/ " + lines[i].ljust(maxLength) + " \\") | |
elif i == len(lines) - 1: | |
print("\\ " + lines[i].ljust(maxLength) + " /") | |
else: | |
print("| " + lines[i].ljust(maxLength) + " |") | |
print(" " + "-" * (maxLength + 2), end='') | |
print(cow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment