Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for What Does the Cow Say? by ablikexe
COW = r'''
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
'''
def cowsay(text):
while text.find(' ') != -1:
text = text.replace(' ', ' ')
lines = []
while len(text) >= 40:
x = text.rfind(' ', 0, 40)
if x != -1:
lines.append(text[:x])
text = text[x+1:]
else:
lines.append(text[:39])
text = text[39:]
lines.append(text)
width = max(len(l) for l in lines)
res = '\n' # ???
res += ' ' + '_'*(width+2) + '\n'
if len(lines) == 1:
res += '< ' + lines[0] + ' >\n'
else:
for i,l in enumerate(lines):
res += '/' if i==0 else '\\' if i==len(lines)-1 else '|'
res += ' ' + l + ' '*(width-len(l)+1)
res += '\\' if i==0 else '/' if i==len(lines)-1 else '|'
res += '\n'
res += ' ' + '-'*(width+2)
res += COW
return res
Aug. 2, 2014
Comments: