Printing a Chunk Of Words
Ben Bacarisse
ben.usenet at bsb.me.uk
Mon Sep 25 22:40:20 EDT 2017
ram at zedat.fu-berlin.de (Stefan Ram) writes:
> Cai Gengyang <gengyangcai at gmail.com> writes:
>> Boolean Operators
>>------------------------
>>True and True is True
>>True and False is False
>>False and True is False
>>False and False is False
>>True or True is True
>>True or False is True
>>False or True is True
>>False or False is False
>>Not True is False
>>Not False is True
>>If I simply want to print a chunk of words and a paragraph
>>like the above, what command should I use ?
>
> The following has about the same size as the original:
>
> S=' Boolean Operators/------------------------/1&1=' +\
> '1/1&0=0/0&1=0/0&0=0//1|1=1/1|0=1/0|1=1/0|0=0//!1=0/!0=1'
> def D(x,y):global S; S=S.replace(x,y)
>
> D('/','\n');D('1','True');D('0','False');D('&',' and ');
> D('|',' or ');D('!','Not ');D('=',' is ');D('!','Not ');
> print(S)
>
> I wrote it just as an attempt to create a shorter piece
> of source code, but I failed.
Think functional! This is 257 characters:
def D(x,y,s):return s.replace(x,y)
print(D('1','True',D('0','False',D('&',' and ',D('|',' or ',D('!','Not ',D('=',' is ',D('!','Not ',""" Boolean Operators
------------------------
1&1=1
1&0=0
0&1=0
0&0=0
1|1=1
1|0=1
0|1=1
0|0=0
!1=0
!0=1"""))))))))
And applying the same idea twice I can get 255:
def D(x,y,s):return s.replace(x,y)
print(eval(D('"D','D("',D(',','","','''"D-,--,D1,True,D0,False,D&, and ,D|, or ,D!,Not ,D=, is ,D!,Not ,"" Boolean Operators
------------
1&1=1
1&0=0
0&1=0
0&0=0
1|1=1
1|0=1
0|1=1
0|0=0
!1=0
!0=1"""))))))))'''))))
--
Ben.
More information about the Python-list
mailing list