Python Boolean Logic

Rick Johnson rantingrickjohnson at gmail.com
Sat Sep 23 01:06:56 EDT 2017


On Friday, September 22, 2017 at 11:46:59 PM UTC-5, Cai Gengyang wrote:
> Input :
> 
> # Assign True or False as appropriate on the lines below!
> 
> # (20 - 10) > 15
> bool_one = False    # We did this one for you!
> 
> # (10 + 17) == 3**16
> # Remember that ** can be read as 'to the power of'. 3**16 is about 43 million.
> bool_two = False
> 
> # 1**2 <= -1
> bool_three = False
> 
> # 40 * 4 >= -4
> bool_four = True
> 
> # 100 != 10**2
> bool_five = False
> 
> print ("bool_one = ", bool_one) 
> print ("bool_two = ", bool_two) 
> print ("bool_three = ", bool_three) 
> print ("bool_four = ", bool_four) 
> print ("bool_five = ", bool_five) 
> 
> 
> Output :
> 
> ('bool_one = ', False)
> ('bool_two = ', False)
> ('bool_three = ', False)
> ('bool_four = ', True)
> ('bool_five = ', False)
> 
> 
> Is my logic / input / output correct ? Thanks a lot ...

This looks like homework, and not a very well designed
homework either. It seems the instructor wants you to
provide the value of each "rich comparison expression" by
assigning a boolean to an enumerated variable. As far as
your "logic and IO being correct", i don't see a request for
any of those things, based on what you provided here. If you
want to check the expressions, just copy/paste them into a
Python console.

    # Python2.x (with dependancy)
    >>> from sanity import *
    >>> if isbadidea('typehints'):
    ...     print 'Duh!'
    ... else:
    ...     print 'Duh!'
    Duh

Yep. My sanity module could have saved the BDFL a lot of
headaches. And possibly his cushy job at GooglePlex...



More information about the Python-list mailing list