from color import * def textJustification(words, l, shift): o = [] c = words[0] print(' '*(shift+1)+'_'*(4+l)) print(' '*shift+'/ _'+'\\'+' '*l+'\\') print(' '*shift+'\\_/__'+'\\'+' '*l+'\\') for x in range(1,len(words)): if len(c)+1+len(words[x])<=l: c = c+' '+words[x] else: e,r = l-len(c),c.split() if len(r)==1: print(' '*(5+shift)+'|'+c+' '*e+'|') else: a = e//(len(r)-1) v = e - a * (len(r)-1) for i in range(len(r)-1): r[i]+=' '*a if v>0: r[i]+=' ' v-=1 r=' '.join(r) print(' '*(5+shift)+'|'+r+'|') c=words[x] print(' '*(5+shift)+'|'+c+' '*(l-len(c))+'|') print(' '*(5+shift)+'|'+' '+'_'*(l-3)+'|___') print(' '*(6+shift) +'\\ /__\\'+' '*(l-2)+'\\') print(' '*(7+shift)+'\\___/'+'_'*(l-2)+'/') print(' '*shift+' ____ _ _ _ _') print(' '*shift+' / __ \\ / \\ / \\ /| / \\') print(' '*shift+'| / | /| | | \\_/') print(' '*shift+'| \\__ | / | | | / \\') print(' '*shift+' \\____/ /__ \\_/ _|_ \\_/') while 1: x = input(setc('red') + 'Enter text: ' + resetc()) y = int(input(setc('green') + 'Paper width: ' + resetc())) v = input(setc('cyan') + 'SHIFT: ' + resetc()) if v.isdigit(): z = int(v) else: z = 22 b = x.split() textJustification(b,y,z)