Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
31-liner: What does the cow say? Nothing solution in Clear category for What Does the Cow Say? by przemyslaw.daniel
from textwrap import wrap
from re import sub
COW = r'''
%s
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
'''
def cowsay(speech):
if len(speech)-len(sub('\w+', '', speech, 1)) > 39:
speech = sub('^ +', ' '*39, speech)
else:
speech = sub('^ +| +$', '#', speech)
speech = sub(' +', ' ', speech)
speech = wrap(speech, 39)
width = max([len(x) for x in speech])+1
speech = [x.ljust(width, ' ') for x in speech]
text = " " + "_" * (width + 1) + "\n"
if len(speech) == 1:
text += "< %s>\n" % speech[0]
else:
text += "/ %s\\\n" % speech[0]
for i in range(0, len(speech)-2):
text += "| %s|\n" % speech[i + 1]
text += "\ %s/\n" % speech[-1]
text += " "+"-"*(width + 1)
return COW % text.replace('#', ' ')
Nov. 15, 2016
Comments: