truth table: test_truth_table_tests


I want to write a program that makes the tests in test_truth_table.py pass without looking at them

requirements

continue the project

  • Make sure you are in the pumping_python folder with pwd in the terminal

    pwd
    

    if the terminal does not show

    .../pumping_python
    

    change directory to the pumping_python folder

  • Once in pumping_python, change directory to the project

    cd truth_table
    

    the terminal shows

    .../pumping_python/truth_table
    
  • I run the tests with pytest-watcher

    uv run pytest-watcher . --now
    

    the terminal is my friend, and shows

    rootdir: .../pumping_python/truth_table
    configfile: pyproject.toml
    collected 20 items
    
    tests/test_binary.py ....................                     [ 80%]
    tests/test_nullary_unary.py ....                              [100%]
    
    ======================== 20 passed in G.HIs ========================
    

RED: make it fail

  • I open truth_table.py from the src folder

  • I delete everything in truth_table.py, the terminal is my friend, and shows 20 failures, I start with the last one

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_negation'
    

    because …

    Can you make the tests pass without looking at how I solve it below? You can come back to compare solutions when you are done.


GREEN: make it pass

  • I add the name to truth_table.py

    1logical_negation
    

    the terminal is my friend, and shows NameError

    NameError: name 'logical_negation' is not defined
    
  • I point it to None to define it

    1logical_negation = None
    

    the terminal is my friend, and shows TypeError

    TypeError: 'NoneType' object is not callable
    

    because I cannot call None like a function.

  • I make it a function

    1# logical_negation
    2def logical_negation():
    3    return None
    

    the terminal is my friend, and shows TypeError

    TypeError: logical_negation() takes
               0 positional arguments but 1 was given
    
  • I add a name in parentheses

    1# logical_negation
    2# def logical_negation():
    3def logical_negation(something):
    4    return None
    

    the terminal is my friend, and shows AssertionError

    AssertionError: None is not true
    

    the assertion expects True.

  • I change None in the return statement to give the test what it wants

    1# logical_negation
    2# def logical_negation():
    3def logical_negation(something):
    4    # return None
    5    return True
    

    the terminal shows AssertionError

    AssertionError: True is not false
    

    the assertion expects False and the function returns True.

  • I change the return statement

    1# logical_negation
    2# def logical_negation():
    3def logical_negation(something):
    4    # return None
    5    # return True
    6    return False
    

    the terminal is my friend, and shows AssertionError

    AssertionError: False is not true
    
  • I change the return statement to see the difference between the input and what the assertion expects, remember the identity_function?

    1# logical_negation
    2# def logical_negation():
    3def logical_negation(something):
    4    # return None
    5    # return True
    6    # return False
    7    return something
    

    the terminal is my friend, and shows AssertionError

    AssertionError: True is not false
    
  • I use not in the return statement

    1# logical_negation
    2# def logical_negation():
    3def logical_negation(something):
    4    # return None
    5    # return True
    6    # return False
    7    # return something
    8    return not something
    

    the terminal shows 19 failed, 1 passed, progress! It also shows AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_identity'
    
  • I add a function for it

     1# logical_negation
     2# def logical_negation():
     3def logical_negation(something):
     4    # return None
     5    # return True
     6    # return False
     7    # return something
     8    return not something
     9
    10
    11def logical_identity():
    12    return None
    

    the terminal is my friend, and shows TypeError

    TypeError: logical_identity() takes
               0 positional arguments but 1 was given
    
  • I add a name in parentheses

    11# def logical_identity():
    12def logical_identity(something):
    13    return None
    

    the terminal is my friend, and shows AssertionError

    AssertionError: None is not true
    
  • I change the return statement for logical_identity to give the test what it wants

    11# def logical_identity():
    12def logical_identity(something):
    13    # return None
    14    return True
    

    the terminal is my friend, and shows AssertionError

    AssertionError: True is not false
    

    the assertion expects False and the function returns True.

  • I change the return statement

    11# def logical_identity():
    12def logical_identity(something):
    13    # return None
    14    # return True
    15    return False
    

    the terminal is my friend, and shows AssertionError

    AssertionError: False is not true
    

    the function returned

  • I change the return statement to see the difference between the input and what the assertion expects

    11# def logical_identity():
    12def logical_identity(something):
    13    # return None
    14    # return True
    15    # return False
    16    return something
    

    the terminal shows 18 failed, 2 passed, more progress! It also shows AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_true'
    
  • I add the function

    11# def logical_identity():
    12def logical_identity(something):
    13    # return None
    14    # return True
    15    # return False
    16    return something
    17
    18
    19def logical_true():
    20    return None
    

    the terminal is my friend, and shows AssertionError

    AssertionError: None is not true
    
  • I change the return statement for logical_true to give the test what it wants

    19def logical_true():
    20    # return None
    21    return True
    

    17 failed, 3 passed. That was simple. the terminal is my friend, and shows AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_false'.
                    Did you mean: 'logical_true'?
    
  • I add the function

    19def logical_true():
    20    # return None
    21    return True
    22
    23
    24def logical_false():
    25    return None
    

    the terminal shows 16 failed, 4 passed, simple again. I am getting it. The terminal also shows AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'tautology'
    
  • I add the function

    24def logical_false():
    25    return None
    26
    27
    28def tautology():
    29    return None
    

    the terminal is my friend, and shows TypeError

    TypeError: tautology() takes
               0 positional arguments but 2 were given
    
  • I add two names in parentheses for the function to take input arguments

    28# def tautology():
    29def tautology(first, second):
    30    return None
    

    the terminal is my friend, and shows AssertionError

    AssertionError: None is not true
    
  • I change None to True in the return statement

    28# def tautology():
    29def tautology(first, second):
    30    # return None
    31    return True
    

    the terminal shows 15 failed, 5 passed, Yes! It also shows AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'project_second'
    
  • I add the function

    28# def tautology():
    29def tautology(first, second):
    30    # return None
    31    return True
    32
    33
    34def project_second():
    35    return None
    

    the terminal is my friend, and shows TypeError

    TypeError: project_second() takes
               0 positional arguments but 2 were given
    
  • I add two names in parentheses for the function to take input arguments

    34# def project_second():
    35def project_second(first, second):
    36    return None
    

    the terminal is my friend, and shows AssertionError

    AssertionError: None is not true
    
  • I change the return statement to give the test what it wants

    34# def project_second():
    35def project_second(first, second):
    36    # return None
    37    return True
    

    the terminal is my friend, and shows AssertionError

    AssertionError: True is not false
    

    the assertion expects False and the function returns True.

  • I change the return statement

    34# def project_second():
    35def project_second(first, second):
    36    # return None
    37    # return True
    38    return False
    

    the terminal is my friend, and shows AssertionError

    AssertionError: False is not true
    

    the function returned

  • I change the return statement to see the difference between the input and what the assertion expects

    34# def project_second():
    35def project_second(first, second):
    36    # return None
    37    # return True
    38    # return False
    39    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, False) is not false
    

    second is False and is equal to the expectation of the assertion.

  • I remove first from the return statement since second is False

    34# def project_second():
    35def project_second(first, second):
    36    # return None
    37    # return True
    38    # return False
    39    # return first, second
    40    return second
    

    the terminal shows 14 failed, 6 passed, and AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'project_first'
    
  • I add a function for it

    34# def project_second():
    35def project_second(first, second):
    36    # return None
    37    # return True
    38    # return False
    39    # return first, second
    40    return second
    41
    42
    43def project_first():
    44    return None
    

    the terminal is my friend, and shows TypeError

    TypeError: project_first() takes
               0 positional arguments but 2 were given
    

    okay, I have seen this before.

  • I add 2 names in the parentheses

    43# def project_first():
    44def project_first(first, second):
    45    return None
    

    the terminal is my friend, and shows AssertionError

    AssertionError: None is not true
    
  • I change the return statement to give the test what it wants

    43# def project_first():
    44def project_first(first, second):
    45    # return None
    46    return True
    

    the terminal is my friend, and shows AssertionError

    AssertionError: True is not false
    

    the assertion expects False and the function returns True.

  • I change the return statement

    43# def project_first():
    44def project_first(first, second):
    45    # return None
    46    # return True
    47    return False
    

    the terminal is my friend, and shows AssertionError

    AssertionError: False is not true
    

    the function returned

  • I change the return statement to see the difference between the input and what the assertion expects

    43# def project_first():
    44def project_first(first, second):
    45    # return None
    46    # return True
    47    # return False
    48    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, True) is not false
    

    second is True and is equal to the expectation of the assertion.

  • I remove second from the return statement since first is False

    43# def project_first():
    44def project_first(first, second):
    45    # return None
    46    # return True
    47    # return False
    48    # return first, second
    49    return first
    

    the terminal shows 13 failed, 7 passed, and AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'negate_second'
    
  • I add a function for negate_second with a return statement to see the difference between the input and what the assertion expects

    43# def project_first():
    44def project_first(first, second):
    45    # return None
    46    # return True
    47    # return False
    48    # return first, second
    49    return first
    50
    51
    52def negate_second(first, second):
    53    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, True) is not false
    
  • I add an if statement to negate_second since first and second are both not False

    52def negate_second(first, second):
    53    if (first, second) == (True, True): return False
    54    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, True) is not false
    
  • I add another if statement

    52def negate_second(first, second):
    53    if (first, second) == (True, True): return False
    54    if (first, second) == (False, True): return False
    55    return first, second
    

    the terminal is my friend, and shows 12 failed, 8 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'negate_first'
    
  • I add a function for it with a return statement to see the difference between the input and what the assertion expects

    52def negate_second(first, second):
    53    if (first, second) == (True, True): return False
    54    if (first, second) == (False, True): return False
    55    return first, second
    56
    57
    58def negate_first(first, second):
    59    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, True)
    
  • I add an if statement since first and second are both not False

    58def negate_first(first, second):
    59    if (first, second) == (True, True): return False
    60    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, False) is not false
    
  • I add another if statement

    58def negate_first(first, second):
    59    if (first, second) == (True, True): return False
    60    if (first, second) == (True, False): return False
    61    return first, second
    

    the terminal is my friend, and shows 11 failed, 9 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'material_non_implication'
    
  • I add a function for material_non_implication with a return statement to see the difference between the input and what the assertion expects

    58def negate_first(first, second):
    59    if (first, second) == (True, True): return False
    60    if (first, second) == (True, False): return False
    61    return first, second
    62
    63
    64def material_non_implication(first, second):
    65    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, True) is not false
    
  • I add an if statement since first and second are both not False

    64def material_non_implication(first, second):
    65    if (first, second) == (True, True): return False
    66    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, True) is not false
    
  • I add another if statement

    64def material_non_implication(first, second):
    65    if (first, second) == (True, True): return False
    66    if (first, second) == (False, True): return False
    67    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, False) is not false
    
  • I add an if statement for it

    64def material_non_implication(first, second):
    65    if (first, second) == (True, True): return False
    66    if (first, second) == (False, True): return False
    67    if (first, second) == (False, False): return False
    68    return first, second
    

    the terminal is my friend, and shows 10 failed, 10 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'material_implication'
    
  • I add a function for material_implication with a return statement to see the difference between the input and what the assertion expects

    64def material_non_implication(first, second):
    65    if (first, second) == (True, True): return False
    66    if (first, second) == (False, True): return False
    67    if (first, second) == (False, False): return False
    68    return first, second
    69
    70
    71def material_implication(first, second):
    72    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, False) is not false
    
  • I add an if statement for it

    71def material_implication(first, second):
    72    if (first, second) == (True, False): return False
    73    return first, second
    

    the terminal is my friend, and shows 9 failed, 11 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_nor'
    
  • I add a function for logical_nor

    71def material_implication(first, second):
    72    if (first, second) == (True, False): return False
    73    return first, second
    74
    75
    76def logical_nor(first, second):
    77    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, True) is not false
    
  • I add an if statement

    76def logical_nor(first, second):
    77    if (first, second) == (True, True): return False
    78    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, False) is not false
    
  • I add another if statement

    76def logical_nor(first, second):
    77    if (first, second) == (True, True): return False
    78    if (first, second) == (True, False): return False
    79    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, True) is not false
    
  • I add an if statement

    76def logical_nor(first, second):
    77    if (first, second) == (True, True): return False
    78    if (first, second) == (True, False): return False
    79    if (first, second) == (False, True): return False
    80    return first, second
    

    the terminal is my friend, and shows 8 failed, 12 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_nand'.
                    Did you mean: 'logical_nor'?
    
  • I add a function for logical_nand

    76def logical_nor(first, second):
    77    if (first, second) == (True, True): return False
    78    if (first, second) == (True, False): return False
    79    if (first, second) == (False, True): return False
    80    return first, second
    81
    82
    83def logical_nand(first, second):
    84    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, True) is not false
    
  • I add an if statement

    83def logical_nand(first, second):
    84    if (first, second) == (True, True): return False
    85    return first, second
    

    the terminal is my friend, and shows 7 failed, 13 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_equality'.
                    Did you mean: 'logical_identity'?
    
  • I add the function

    83def logical_nand(first, second):
    84    if (first, second) == (True, True): return False
    85    return first, second
    86
    87
    88def logical_equality(first, second):
    89    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, False) is not false
    
  • I add an if statement

    88def logical_equality(first, second):
    89    if (first, second) == (True, False): return False
    90    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, True) is not false
    
  • I add another if statement

    88def logical_equality(first, second):
    89    if (first, second) == (True, False): return False
    90    if (first, second) == (False, True): return False
    91    return first, second
    

    the terminal is my friend, and shows 6 failed, 14 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_disjunction'
    
  • I add a function for logical_disjunction

    88def logical_equality(first, second):
    89    if (first, second) == (True, False): return False
    90    if (first, second) == (False, True): return False
    91    return first, second
    92
    93
    94def logical_disjunction(first, second):
    95    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, False) is not false
    
  • I add an if statement

    94def logical_disjunction(first, second):
    95    if (first, second) == (False, False): return False
    96    return first, second
    

    the terminal is my friend, and shows 5 failed, 15 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'logical_conjunction'.
                    Did you mean: 'logical_disjunction'?
    
  • I add a function for logical_conjunction

     94def logical_disjunction(first, second):
     95    if (first, second) == (False, False): return False
     96    return first, second
     97
     98
     99def logical_conjunction(first, second):
    100    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, False) is not false
    
  • I add an if statement

     99def logical_conjunction(first, second):
    100    if (first, second) == (True, False): return False
    101    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, True) is not false
    
  • I add an if statement

     99def logical_conjunction(first, second):
    100    if (first, second) == (True, False): return False
    101    if (first, second) == (False, True): return False
    102    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, False) is not false
    
  • I add another if statement

     99def logical_conjunction(first, second):
    100    if (first, second) == (True, False): return False
    101    if (first, second) == (False, True): return False
    102    if (first, second) == (False, False): return False
    103    return first, second
    

    the terminal is my friend, and shows 4 failed, 16 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'exclusive_disjunction'
    
  • I add a function for exclusive_disjunction

     99def logical_conjunction(first, second):
    100    if (first, second) == (True, False): return False
    101    if (first, second) == (False, True): return False
    102    if (first, second) == (False, False): return False
    103    return first, second
    104
    105
    106def exclusive_disjunction(first, second):
    107    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, True) is not false
    
  • I add an if statement

    106def exclusive_disjunction(first, second):
    107    if (first, second) == (True, True): return False
    108    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, False) is not false
    
  • I add another if statement

    106def exclusive_disjunction(first, second):
    107    if (first, second) == (True, True): return False
    108    if (first, second) == (False, False): return False
    109    return first, second
    

    the terminal is my friend, and shows 3 failed, 17 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'converse_non_implication'.
                    Did you mean: 'material_non_implication'?
    
  • I add converse_non_implication

    106def exclusive_disjunction(first, second):
    107    if (first, second) == (True, True): return False
    108    if (first, second) == (False, False): return False
    109    return first, second
    110
    111
    112def converse_non_implication(first, second):
    113    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, True) is not false
    
  • I add an if statement

    112def converse_non_implication(first, second):
    113    if (first, second) == (True, True): return False
    114    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, False) is not false
    
  • I add another if statement

    112def converse_non_implication(first, second):
    113    if (first, second) == (True, True): return False
    114    if (first, second) == (True, False): return False
    115    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, False) is not false
    
  • I add an if statement

    112def converse_non_implication(first, second):
    113    if (first, second) == (True, True): return False
    114    if (first, second) == (True, False): return False
    115    if (first, second) == (False, False): return False
    116    return first, second
    

    the terminal is my friend, and shows 2 passed, 18 failed for AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'converse_implication'.
                    Did you mean: 'converse_non_implication'?
    
  • I add converse_implication

    112def converse_non_implication(first, second):
    113    if (first, second) == (True, True): return False
    114    if (first, second) == (True, False): return False
    115    if (first, second) == (False, False): return False
    116    return first, second
    117
    118
    119def converse_implication(first, second):
    120    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, True) is not false
    
  • I add an if statement

    119def converse_implication(first, second):
    120    if (first, second) == (False, True): return False
    121    return first, second
    

    the terminal is my friend, and shows 1 failed, 19 passed with AttributeError

    AttributeError: module 'src.truth_table'
                    has no attribute 'contradiction'
    
  • I add contradiction

    119def converse_implication(first, second):
    120    if (first, second) == (False, True): return False
    121    return first, second
    122
    123
    124def contradiction(first, second):
    125    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, True) is not false
    
  • I add an if statement

    124def contradiction(first, second):
    125    if (first, second) == (True, True): return False
    126    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (True, False) is not false
    
  • I add another if statement

    124def contradiction(first, second):
    125    if (first, second) == (True, True): return False
    126    if (first, second) == (True, False): return False
    127    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, True) is not false
    
  • I add another if statement

    124def contradiction(first, second):
    125    if (first, second) == (True, True): return False
    126    if (first, second) == (True, False): return False
    127    if (first, second) == (False, True): return False
    128    return first, second
    

    the terminal is my friend, and shows AssertionError

    AssertionError: (False, False) is not false
    
  • I add an if statement

    124def contradiction(first, second):
    125    if (first, second) == (True, True): return False
    126    if (first, second) == (True, False): return False
    127    if (first, second) == (False, True): return False
    128    if (first, second) == (False, False): return False
    129    return first, second
    

    the terminal is my friend, and shows

    ======================== 20 passed in G.HIs ========================
    

All the tests are passing and the world is a better place than when I started! I am going home.


REFACTOR: make it better

Wait, there is more… Since all the tests are passing, I can play with the functions I have to make them simpler and understand why my solutions work.

  • contradiction returns False in 4 cases, with 2 inputs there are only 4 cases. I add a return statement

    124def contradiction(first, second):
    125    # if (first, second) == (True, True): return False
    126    # if (first, second) == (True, False): return False
    127    # if (first, second) == (False, True): return False
    128    # if (first, second) == (False, False): return False
    129    # return first, second
    130    return False
    

    the test is still green.

  • I remove the commented lines from contradiction

    124def contradiction(first, second):
    125    return False
    

  • converse_implication returns False in only one case. I write out the if statement for that case, to make it clearer

    119def converse_implication(first, second):
    120    # if (first, second) == (False, True): return False
    121    if first == False and second == True:
    122        return False
    123    return first, second
    

    still green.

  • I change the statement with not and True

    119def converse_implication(first, second):
    120    # if (first, second) == (False, True): return False
    121    # if first == False and second == True:
    122    if not first == True and second == True:
    123        return False
    124    return first, second
    

    green.

  • I remove == True

    119def converse_implication(first, second):
    120    # if (first, second) == (False, True): return False
    121    # if first == False and second == True:
    122    # if not first == True and second == True:
    123    if not first and second:
    124        return False
    125    return first, second
    

    still green.

  • I add a return statement because if something: return False can be written as return not (something)

    119def converse_implication(first, second):
    120    # if (first, second) == (False, True): return False
    121    # if first == False and second == True:
    122    # if not first == True and second == True:
    123    # if not first and second:
    124    #     return False
    125    # return first, second
    126    return not (not first and second)
    

    the test is still green.

  • I “multiply not” by the things in the parentheses

    119def converse_implication(first, second):
    120    # if (first, second) == (False, True): return False
    121    # if first == False and second == True:
    122    # if not first == True and second == True:
    123    # if not first and second:
    124    #     return False
    125    # return first, second
    126    # return not (not first and second)
    127    return (not not first) (not and) (not second)
    

    the terminal is my friend, and shows SyntaxError

    SyntaxError: invalid syntax
    
  • I change not and to or

    119def converse_implication(first, second):
    120    # if (first, second) == (False, True): return False
    121    # if first == False and second == True:
    122    # if not first == True and second == True:
    123    # if not first and second:
    124    #     return False
    125    # return first, second
    126    # return not (not first and second)
    127    # return (not not first) (not and) (not second)
    128    return (not not first) or (not second)
    

    the test is green again.

  • I remove not not because two nots make a right?

    119def converse_implication(first, second):
    120    # if (first, second) == (False, True): return False
    121    # if first == False and second == True:
    122    # if not first == True and second == True:
    123    # if not first and second:
    124    #     return False
    125    # return first, second
    126    # return not (not first and second)
    127    # return (not not first) (not and) (not second)
    128    # return (not not first) or (not second)
    129    return first or not second
    
  • I remove the commented lines

    119def converse_implication(first, second):
    120    return first or not second
    121
    122
    123def contradiction(first, second):
    124    return False
    

  • I add an if statement for the only case that returns True in converse_non_implication

    112def converse_non_implication(first, second):
    113    # if (first, second) == (True, True): return False
    114    # if (first, second) == (True, False): return False
    115    # if (first, second) == (False, False): return False
    116    # return first, second
    117    if first == False and second == True:
    118        return True
    119    else:
    120        return False
    

    the test is still green.

  • I change if first == False to terms of True

    112def converse_non_implication(first, second):
    113    # if (first, second) == (True, True): return False
    114    # if (first, second) == (True, False): return False
    115    # if (first, second) == (False, False): return False
    116    # return first, second
    117    # if first == False and second == True:
    118    if not first == True and second == True:
    119        return True
    120    else:
    121        return False
    

    green.

  • I remove == True

    112def converse_non_implication(first, second):
    113    # if (first, second) == (True, True): return False
    114    # if (first, second) == (True, False): return False
    115    # if (first, second) == (False, False): return False
    116    # return first, second
    117    # if first == False and second == True:
    118    # if not first == True and second == True:
    119    if not first and second:
    120        return True
    121    else:
    122        return False
    

    still green.

  • I add a return statement because if something: return True can be written as return something since something is grouped as True

    112def converse_non_implication(first, second):
    113    # if (first, second) == (True, True): return False
    114    # if (first, second) == (True, False): return False
    115    # if (first, second) == (False, False): return False
    116    # return first, second
    117    # if first == False and second == True:
    118    # if not first == True and second == True:
    119    # if not first and second:
    120    #     return True
    121    # else:
    122    #     return False
    123    return not first and second
    

    the test is still green.

  • I remove the commented lines

    112def converse_non_implication(first, second):
    113    return not first and second
    114
    115
    116def converse_implication(first, second):
    117    return first or not second
    118
    119
    120def contradiction(first, second):
    121    return False
    

  • I make the if statements in exclusive_disjunction simpler

    106def exclusive_disjunction(first, second):
    107    # if (first, second) == (True, True): return False
    108    # if (first, second) == (False, False): return False
    109    # return first, second
    110    if first == True and second == True:
    111        return False
    112    if first == False and second == False:
    113        return False
    114    return True
    

    the test is still green.

  • I change the new second if statement with not and True

    106def exclusive_disjunction(first, second):
    107    # if (first, second) == (True, True): return False
    108    # if (first, second) == (False, False): return False
    109    # return first, second
    110    if first == True and second == True:
    111        return False
    112    # if first == False and second == False:
    113    if not first == True and not second == True:
    114        return False
    115    return True
    

    still green.

  • I remove == True

    106def exclusive_disjunction(first, second):
    107    # if (first, second) == (True, True): return False
    108    # if (first, second) == (False, False): return False
    109    # return first, second
    110    # if first == True and second == True:
    111    if first and second:
    112        return False
    113    # if first == False and second == False:
    114    # if not first == True and not second == True:
    115    if not first and not second:
    116        return False
    117    return True
    

    green.

  • I write everything in the second if statement with not because it happens two times in the line, I might as well make it three

    106def exclusive_disjunction(first, second):
    107    # if (first, second) == (True, True): return False
    108    # if (first, second) == (False, False): return False
    109    # return first, second
    110    # if first == True and second == True:
    111    if first and second:
    112        return False
    113    # if first == False and second == False:
    114    # if not first == True and not second == True:
    115    # if not first and not second:
    116    if (not first) (not or) (not second):
    117        return False
    118    return True
    

    the terminal is my friend, and shows SyntaxError

    SyntaxError: invalid syntax
    
  • I factor out the nots

    106def exclusive_disjunction(first, second):
    107    # if (first, second) == (True, True): return False
    108    # if (first, second) == (False, False): return False
    109    # return first, second
    110    # if first == True and second == True:
    111    if first and second:
    112        return False
    113    # if first == False and second == False:
    114    # if not first == True and not second == True:
    115    # if not first and not second:
    116    # if (not first) (not or) (not second):
    117    if not (first or second):
    118        return False
    119    return True
    

    the test is green .

  • I put the two if statements together as one

    106def exclusive_disjunction(first, second):
    107    # if (first, second) == (True, True): return False
    108    # if (first, second) == (False, False): return False
    109    # return first, second
    110    # if first == True and second == True:
    111    # if first and second:
    112    #     return False
    113    # if first == False and second == False:
    114    # if not first == True and not second == True:
    115    # if not first and not second:
    116    # if (not first) (not or) (not second):
    117    # if not (first or second):
    118    if (
    119        (first and second)
    120        or
    121        (not (first or second))
    122    ):
    123        return False
    124    return True
    

    the test is still green.

  • I add a return statement because if something: return False can be written as return not (something)

    106def exclusive_disjunction(first, second):
    107    # if (first, second) == (True, True): return False
    108    # if (first, second) == (False, False): return False
    109    # return first, second
    110    # if first == True and second == True:
    111    # if first and second:
    112    #     return False
    113    # if first == False and second == False:
    114    # if not first == True and not second == True:
    115    # if not first and not second:
    116    # if (not first) (not or) (not second):
    117    # if not (first or second):
    118    # if (
    119    #     (first and second)
    120    #     or
    121    #     (not (first or second))
    122    # ):
    123    #     return False
    124    # return True
    125    return not (
    126        (first and second)
    127        or
    128        (not (first or second))
    129    )
    

    still green.

  • I “multiply” not by everything in the parentheses since it happens two times in the line

    106def exclusive_disjunction(first, second):
    107    # if (first, second) == (True, True): return False
    108    # if (first, second) == (False, False): return False
    109    # return first, second
    110    # if first == True and second == True:
    111    # if first and second:
    112    #     return False
    113    # if first == False and second == False:
    114    # if not first == True and not second == True:
    115    # if not first and not second:
    116    # if (not first) (not or) (not second):
    117    # if not (first or second):
    118    # if (
    119    #     (first and second)
    120    #     or
    121    #     (not (first or second))
    122    # ):
    123    #     return False
    124    # return True
    125    # return not (
    126    #     (first and second)
    127    #     or
    128    #     (not (first or second))
    129    # )
    130    return (
    131        (not (first and second))
    132        (not or)
    133        (not (not (first or second)))
    134    )
    

    the terminal shows SyntaxError

    SyntaxError: invalid syntax
    
  • I change not or to and

    130    return (
    131        (not (first and second))
    132        # (not or)
    133        and
    134        (not (not (first or second)))
    135    )
    

    the test is green again.

  • I remove not not because “the negation of a negation is …”

    130    return (
    131        (not (first and second))
    132        # (not or)
    133        and
    134        # (not (not (first or second)))
    135        (first or second)
    136    )
    

    green.

  • I remove the commented lines from exclusive_disjunction

    106def exclusive_disjunction(first, second):
    107    return (not (first and second)) and (first or second)
    108
    109
    110def converse_non_implication(first, second):
    111    return not first and second
    112
    113
    114def converse_implication(first, second):
    115    return first or not second
    116
    117
    118def contradiction(first, second):
    119    return False
    

  • logical_conjunction has only one case that returns True. I add an if statement for it

     99def logical_conjunction(first, second):
    100    # if (first, second) == (True, False): return False
    101    # if (first, second) == (False, True): return False
    102    # if (first, second) == (False, False): return False
    103    # return first, second
    104    if first == True and second == True:
    105        return True
    106    else:
    107        return False
    

    the test is still green.

  • I remove == True

     99def logical_conjunction(first, second):
    100    # if (first, second) == (True, False): return False
    101    # if (first, second) == (False, True): return False
    102    # if (first, second) == (False, False): return False
    103    # return first, second
    104    # if first == True and second == True:
    105    if first and second:
    106        return True
    107    else:
    108        return False
    

    still green.

  • I add a return statement because if something: return True can be written as return something since something is grouped as True

     99def logical_conjunction(first, second):
    100    # if (first, second) == (True, False): return False
    101    # if (first, second) == (False, True): return False
    102    # if (first, second) == (False, False): return False
    103    # return first, second
    104    # if first == True and second == True:
    105    # if first and second:
    106    #     return True
    107    # else:
    108    #     return False
    109    return first and second
    

    green.

  • I remove the commented lines from logical_conjunction

     99def logical_conjunction(first, second):
    100    return first and second
    101
    102
    103def exclusive_disjunction(first, second):
    104    return (not (first and second)) and (first or second)
    

  • logical_disjunction has only one case that returns False, I break up the if statement

     94def logical_disjunction(first, second):
     95    # if (first, second) == (False, False): return False
     96    # return first, second
     97    if first == False and second == False:
     98        return False
     99    else:
    100        return True
    

    the test is still green.

  • I then change the if statement with not and True

     94def logical_disjunction(first, second):
     95    # if (first, second) == (False, False): return False
     96    # return first, second
     97    # if first == False and second == False:
     98    if not first == True and not second == True:
     99        return False
    100    else:
    101        return True
    

    still green.

  • I remove == True

     94def logical_disjunction(first, second):
     95    # if (first, second) == (False, False): return False
     96    # return first, second
     97    # if first == False and second == False:
     98    # if not first == True and not second == True:
     99    if not first and not second:
    100        return False
    101    else:
    102        return True
    

    green.

  • I change the statement with not since it happens two times

     94def logical_disjunction(first, second):
     95    # if (first, second) == (False, False): return False
     96    # return first, second
     97    # if first == False and second == False:
     98    # if not first == True and not second == True:
     99    # if not first and not second:
    100    if (not first) (not or) (not second):
    101        return False
    102    else:
    103        return True
    

    the terminal is my friend, and shows SyntaxError

    SyntaxError: invalid syntax
    
  • I factor out not

     94def logical_disjunction(first, second):
     95    # if (first, second) == (False, False): return False
     96    # return first, second
     97    # if first == False and second == False:
     98    # if not first == True and not second == True:
     99    # if not first and not second:
    100    # if (not first) (not or) (not second):
    101    if not (first or second):
    102        return False
    103    else:
    104        return True
    

    the test is green again.

  • I add a return statement for the opposite of the if statement because if something: return False can be written as return not (something)

     94def logical_disjunction(first, second):
     95    # if (first, second) == (False, False): return False
     96    # return first, second
     97    # if first == False and second == False:
     98    # if not first == True and not second == True:
     99    # if not first and not second:
    100    # if (not first) (not or) (not second):
    101    # if not (first or second):
    102    #     return False
    103    # else:
    104    #     return True
    105    return not (not (first or second))
    

    still green.

  • I remove not not

     94def logical_disjunction(first, second):
     95    # if (first, second) == (False, False): return False
     96    # return first, second
     97    # if first == False and second == False:
     98    # if not first == True and not second == True:
     99    # if not first and not second:
    100    # if (not first) (not or) (not second):
    101    # if not (first or second):
    102    #     return False
    103    # else:
    104    #     return True
    105    # return not (not (first or second))
    106    return first or second
    

    the test is still green.

  • I remove the commented lines from logical_disjunction

    94def logical_disjunction(first, second):
    95    return first or second
    96
    97
    98def logical_conjunction(first, second):
    99    return first and second
    

  • I break up the if statements in logical_equality

    88def logical_equality(first, second):
    89    # if (first, second) == (True, False): return False
    90    # if (first, second) == (False, True): return False
    91    # return first, second
    92    if first == True and second == False:
    93        return False
    94    if first == False and second == True:
    95        return False
    96    return True
    

    the test is still green.

  • I change the if statements with not and True

    88def logical_equality(first, second):
    89    # if (first, second) == (True, False): return False
    90    # if (first, second) == (False, True): return False
    91    # return first, second
    92    # if first == True and second == False:
    93    if first == True and not second == True:
    94        return False
    95    # if first == False and second == True:
    96    if not first == True and second == True:
    97        return False
    98    return True
    

    still green.

  • I remove == True

     88def logical_equality(first, second):
     89    # if (first, second) == (True, False): return False
     90    # if (first, second) == (False, True): return False
     91    # return first, second
     92    # if first == True and second == False:
     93    # if first == True and not second == True:
     94    if first and not second:
     95        return False
     96    # if first == False and second == True:
     97    # if not first == True and second == True:
     98    if not first and second:
     99        return False
    100    return True
    

    green.

  • I put the two if statements together as one

     88def logical_equality(first, second):
     89    # if (first, second) == (True, False): return False
     90    # if (first, second) == (False, True): return False
     91    # return first, second
     92    # if first == True and second == False:
     93    # if first == True and not second == True:
     94    # if first and not second:
     95    #     return False
     96    # if first == False and second == True:
     97    # if not first == True and second == True:
     98    # if not first and second:
     99    if (
    100        (first and not second)
    101        or
    102        (not first and second)
    103    ):
    104        return False
    105    return True
    

    still green.

  • I add a return statement because …

     88def logical_equality(first, second):
     89    # if (first, second) == (True, False): return False
     90    # if (first, second) == (False, True): return False
     91    # return first, second
     92    # if first == True and second == False:
     93    # if first == True and not second == True:
     94    # if first and not second:
     95    #     return False
     96    # if first == False and second == True:
     97    # if not first == True and second == True:
     98    # if not first and second:
     99    # if (
    100    #     (first and not second)
    101    #     or
    102    #     (not first and second)
    103    # ):
    104    #     return False
    105    # return True
    106    return not (
    107        (first and not second)
    108        or
    109        (not first and second)
    110    )
    

    the test is still green.

  • I multiply not by all the symbols in parentheses

     88def logical_equality(first, second):
     89    # if (first, second) == (True, False): return False
     90    # if (first, second) == (False, True): return False
     91    # return first, second
     92    # if first == True and second == False:
     93    # if first == True and not second == True:
     94    # if first and not second:
     95    #     return False
     96    # if first == False and second == True:
     97    # if not first == True and second == True:
     98    # if not first and second:
     99    # if (
    100    #     (first and not second)
    101    #     or
    102    #     (not first and second)
    103    # ):
    104    #     return False
    105    # return True
    106    # return not (
    107    #     (first and not second)
    108    #     or
    109    #     (not first and second)
    110    # )
    111    return (
    112        (not (first and not second))
    113        (not or)
    114        (not (not first and second))
    115    )
    

    the terminal is my friend, and shows SyntaxError

    SyntaxError: invalid syntax
    
  • I change not or to and

    111    return (
    112        (not (first and not second))
    113        # (not or)
    114        and
    115        (not (not first and second))
    116    )
    

    the test is green again.

  • I multiply not by the symbols in the first part of the statement

    111    return (
    112        # (not (first and not second))
    113        ((not first) (not and) (not not second))
    114        # (not or)
    115        and
    116        (not (not first and second))
    117    )
    

    the terminal is my friend, and shows SyntaxError

    SyntaxError: invalid syntax
    
  • I change not and to or

    111    return (
    112        # (not (first and not second))
    113        # ((not first) (not and) (not not second))
    114        ((not first) or (not not second))
    115        # (not or)
    116        and
    117        (not (not first and second))
    118    )
    

    the test is green again.

  • I remove not not

    111    return (
    112        # (not (first and not second))
    113        # ((not first) (not and) (not not second))
    114        # ((not first) or (not not second))
    115        (not first or second)
    116        # (not or)
    117        and
    118        (not (not first and second))
    119    )
    

    still green.

  • I multiply not by the symbols in the second part of the statement

    111    return (
    112        # (not (first and not second))
    113        # ((not first) (not and) (not not second))
    114        # ((not first) or (not not second))
    115        (not first or second)
    116        # (not or)
    117        and
    118        # (not (not first and second))
    119        ((not not first) (not and) (not second))
    120    )
    

    the terminal is my friend, and shows SyntaxError

    SyntaxError: invalid syntax
    
  • I change not and to or

    111    return (
    112        # (not (first and not second))
    113        # ((not first) (not and) (not not second))
    114        # ((not first) or (not not second))
    115        (not first or second)
    116        # (not or)
    117        and
    118        # (not (not first and second))
    119        # ((not not first) (not and) (not second))
    120        ((not not first) or (not second))
    121    )
    

    the test is green again.

  • I remove not not

    111    return (
    112        # (not (first and not second))
    113        # ((not first) (not and) (not not second))
    114        # ((not first) or (not not second))
    115        (not first or second)
    116        # (not or)
    117        and
    118        # (not (not first and second))
    119        # ((not not first) (not and) (not second))
    120        # ((not not first) or (not second))
    121        (first or not second)
    122    )
    

    the test is still green.

  • I remove the commented lines from logical_equality

    88def logical_equality(first, second):
    89    return (not first or second) and (first or not second)
    90
    91
    92def logical_disjunction(first, second):
    93    return first or second
    

  • I make the if statement in logical_nand simpler

    83def logical_nand(first, second):
    84    # if (first, second) == (True, True): return False
    85    # return first, second
    86    if first == True and second == True:
    87        return False
    88    else:
    89        return True
    

    the test is still green.

  • I remove == True

    83def logical_nand(first, second):
    84    # if (first, second) == (True, True): return False
    85    # return first, second
    86    # if first == True and second == True:
    87    if first and second:
    88        return False
    89    else:
    90        return True
    

    still green.

  • I add a return statement because …

    83def logical_nand(first, second):
    84    # if (first, second) == (True, True): return False
    85    # return first, second
    86    # if first == True and second == True:
    87    # if first and second:
    88    #     return False
    89    # else:
    90    #     return True
    91    return not (first and second)
    

    green.

  • I remove the commented lines from logical_nand

    83def logical_nand(first, second):
    84    return not (first and second)
    85
    86
    87def logical_equality(first, second):
    88    return (not first or second) and (first or not second)
    

  • logical_nor has only one case that returns True. I add an if statement for it

    76def logical_nor(first, second):
    77    # if (first, second) == (True, True): return False
    78    # if (first, second) == (True, False): return False
    79    # if (first, second) == (False, True): return False
    80    # return first, second
    81    if first == False and second == False:
    82        return True
    83    else:
    84        return False
    

    the test is still green.

  • I use not to write the if statement in terms of True

    76def logical_nor(first, second):
    77    # if (first, second) == (True, True): return False
    78    # if (first, second) == (True, False): return False
    79    # if (first, second) == (False, True): return False
    80    # return first, second
    81    # if first == False and second == False:
    82    if not first == True and not second == True:
    83        return True
    84    else:
    85        return False
    

    still green.

  • I remove == True

    76def logical_nor(first, second):
    77    # if (first, second) == (True, True): return False
    78    # if (first, second) == (True, False): return False
    79    # if (first, second) == (False, True): return False
    80    # return first, second
    81    # if first == False and second == False:
    82    # if not first == True and not second == True:
    83    if not first and not second:
    84        return True
    85    else:
    86        return False
    

    green.

  • I add a return statement

    76def logical_nor(first, second):
    77    # if (first, second) == (True, True): return False
    78    # if (first, second) == (True, False): return False
    79    # if (first, second) == (False, True): return False
    80    # return first, second
    81    # if first == False and second == False:
    82    # if not first == True and not second == True:
    83    # if not first and not second:
    84    #     return True
    85    # else:
    86    #     return False
    87    return not first and not second
    

    still green.

  • I write the statement with not because it happens 2 times

    76def logical_nor(first, second):
    77    # if (first, second) == (True, True): return False
    78    # if (first, second) == (True, False): return False
    79    # if (first, second) == (False, True): return False
    80    # return first, second
    81    # if first == False and second == False:
    82    # if not first == True and not second == True:
    83    # if not first and not second:
    84    #     return True
    85    # else:
    86    #     return False
    87    # return not first and not second
    88    return (not first) (not or) (not second)
    

    the terminal is my friend, and shows SyntaxError

    SyntaxError: invalid syntax
    
  • I factor out not

    76def logical_nor(first, second):
    77    # if (first, second) == (True, True): return False
    78    # if (first, second) == (True, False): return False
    79    # if (first, second) == (False, True): return False
    80    # return first, second
    81    # if first == False and second == False:
    82    # if not first == True and not second == True:
    83    # if not first and not second:
    84    #     return True
    85    # else:
    86    #     return False
    87    # return not first and not second
    88    # return (not first) (not or) (not second)
    89    return not (first or second)
    

    the test is green again.

  • I remove the commented lines from logical_nor

    76def logical_nor(first, second):
    77    return not (first or second)
    78
    79
    80def logical_nand(first, second):
    81    return not (first and second)
    

  • I add return statement for the if statement of material_implication because if something: return False can be written as return not (something)

    71def material_implication(first, second):
    72    # if (first, second) == (True, False): return False
    73    # return first, second
    74    return not ((first, second) == (True, False))
    

    the test is still green.

  • I break up the return statement to make it simpler

    71def material_implication(first, second):
    72    # if (first, second) == (True, False): return False
    73    # return first, second
    74    # return not ((first, second) == (True, False))
    75    return not (first == True and second == False)
    

    still green.

  • I use not to rewrite it in terms of True

    71def material_implication(first, second):
    72    # if (first, second) == (True, False): return False
    73    # return first, second
    74    # return not ((first, second) == (True, False))
    75    # return not (first == True and second == False)
    76    return not (first == True and not second == True)
    

    green.

  • I remove == True

    71def material_implication(first, second):
    72    # if (first, second) == (True, False): return False
    73    # return first, second
    74    # return not ((first, second) == (True, False))
    75    # return not (first == True and second == False)
    76    # return not (first == True and not second == True)
    77    return not (first and not second)
    

    still green.

  • I multiply not by everything in parentheses

    71def material_implication(first, second):
    72    # if (first, second) == (True, False): return False
    73    # return first, second
    74    # return not ((first, second) == (True, False))
    75    # return not (first == True and second == False)
    76    # return not (first == True and not second == True)
    77    # return not (first and not second)
    78    return (not first) (not and) (not not second)
    

    the terminal is my friend, and shows SyntaxError

    SyntaxError: invalid syntax
    
  • I change not and to or

    71def material_implication(first, second):
    72    # if (first, second) == (True, False): return False
    73    # return first, second
    74    # return not ((first, second) == (True, False))
    75    # return not (first == True and second == False)
    76    # return not (first == True and not second == True)
    77    # return not (first and not second)
    78    # return (not first) (not and) (not not second)
    79    return (not first) or (not not second)
    

    the test is green again.

  • I remove not not

    71def material_implication(first, second):
    72    # if (first, second) == (True, False): return False
    73    # return first, second
    74    # return not ((first, second) == (True, False))
    75    # return not (first == True and second == False)
    76    # return not (first == True and not second == True)
    77    # return not (first and not second)
    78    # return (not first) (not and) (not not second)
    79    # return (not first) or (not not second)
    80    return not first or second
    

    the test is still green.

  • I remove the commented lines from material_implication

    71def material_implication(first, second):
    72    return not first or second
    73
    74
    75def logical_nor(first, second):
    76    return not (first or second)
    

  • material_non_implication has 3 cases that return False. I add a return statement for the case that returns True

    64def material_non_implication(first, second):
    65    # if (first, second) == (True, True): return False
    66    # if (first, second) == (False, True): return False
    67    # if (first, second) == (False, False): return False
    68    # return first, second
    69    return (first, second) == (True, False)
    

    the test is still green.

  • I make the return statement simpler

    64def material_non_implication(first, second):
    65    # if (first, second) == (True, True): return False
    66    # if (first, second) == (False, True): return False
    67    # if (first, second) == (False, False): return False
    68    # return first, second
    69    # return (first, second) == (True, False)
    70    return first == True and second == False
    

    still green.

  • I use not to write it in terms of True

    64def material_non_implication(first, second):
    65    # if (first, second) == (True, True): return False
    66    # if (first, second) == (False, True): return False
    67    # if (first, second) == (False, False): return False
    68    # return first, second
    69    # return (first, second) == (True, False)
    70    # return first == True and second == False
    71    return first == True and not second == True
    

    green.

  • I remove == True

    64def material_non_implication(first, second):
    65    # if (first, second) == (True, True): return False
    66    # if (first, second) == (False, True): return False
    67    # if (first, second) == (False, False): return False
    68    # return first, second
    69    # return (first, second) == (True, False)
    70    # return first == True and second == False
    71    # return first == True and not second == True
    72    return first and not second
    

    still green.

  • I remove the commented lines from material_non_implication

    64def material_non_implication(first, second):
    65    return first and not second
    66
    67
    68def material_implication(first, second):
    69    return not first or second
    

  • first is True in the two cases where negate_first returns False, I add an if statement for them

    58def negate_first(first, second):
    59    # if (first, second) == (True, True): return False
    60    # if (first, second) == (True, False): return False
    61    # return first, second
    62    if first == True:
    63        return False
    64    else:
    65        return True
    

    the test is still green.

  • I add a return statement because …

    58def negate_first(first, second):
    59    # if (first, second) == (True, True): return False
    60    # if (first, second) == (True, False): return False
    61    # return first, second
    62    # if first == True:
    63    #     return False
    64    # else:
    65    #     return True
    66    return not first == True
    

    still green.

  • I remove == True

    58def negate_first(first, second):
    59    # if (first, second) == (True, True): return False
    60    # if (first, second) == (True, False): return False
    61    # return first, second
    62    # if first == True:
    63    #     return False
    64    # else:
    65    #     return True
    66    # return not first == True
    67    return not first
    

    green.

  • I remove the commented lines from negate_first

    58def negate_first(first, second):
    59    return not first
    60
    61
    62def material_non_implication(first, second):
    63    return first and not second
    

  • second is True in the two cases where negate_second returns False. I add an if statement for them

    52def negate_second(first, second):
    53    # if (first, second) == (True, True): return False
    54    # if (first, second) == (False, True): return False
    55    # return first, second
    56    if second == True:
    57        return False
    58    else:
    59        return True
    

    the test is still green.

  • I add a return statement because if something == False: can be written as return not something

    52def negate_second(first, second):
    53    # if (first, second) == (True, True): return False
    54    # if (first, second) == (False, True): return False
    55    # return first, second
    56    # if second == True:
    57    #     return False
    58    # else:
    59    #     return True
    60    return not second == True
    

    still green.

  • I remove == True

    52def negate_second(first, second):
    53    # if (first, second) == (True, True): return False
    54    # if (first, second) == (False, True): return False
    55    # return first, second
    56    # if second == True:
    57    #     return False
    58    # else:
    59    #     return True
    60    # return not second == True
    61    return not second
    

    green.

  • I remove the commented lines from truth_table.py because all the other functions are already simple

     1def logical_negation(something):
     2    return not something
     3
     4
     5def logical_identity(something):
     6    return something
     7
     8
     9def logical_true():
    10    return True
    11
    12
    13def logical_false():
    14    return None
    15
    16
    17def tautology(first, second):
    18    return True
    19
    20
    21def project_second(first, second):
    22    return second
    23
    24
    25def project_first(first, second):
    26    return first
    27
    28
    29def negate_second(first, second):
    30    return not second
    31
    32
    33def negate_first(first, second):
    34    return not first
    35
    36
    37def material_non_implication(first, second):
    38    return first and not second
    39
    40
    41def material_implication(first, second):
    42    return not first or second
    43
    44
    45def logical_nor(first, second):
    46    return not (first or second)
    47
    48
    49def logical_nand(first, second):
    50    return not (first and second)
    51
    52
    53def logical_equality(first, second):
    54    return (not first or second) and (first or not second)
    55
    56
    57def logical_disjunction(first, second):
    58    return first or second
    59
    60
    61def logical_conjunction(first, second):
    62    return first and second
    63
    64
    65def exclusive_disjunction(first, second):
    66    return (not (first and second)) and (first or second)
    67
    68
    69def converse_non_implication(first, second):
    70    return not first and second
    71
    72
    73def converse_implication(first, second):
    74    return first or not second
    75
    76
    77def contradiction(first, second):
    78    return False
    

close the project

  • I close truth_table.py

  • I click in the terminal where the tests are running

  • I use q on the keyboard to leave the tests. The terminal goes back to the command line.

  • I change directory to the parent of truth_table

    cd ..
    

    the terminal shows

    .../pumping_python
    

    I am back in the pumping_python directory


review

I ran tests using booleans which can be False or True, for the operations of the Truth Table from Mathematics

and

All the binary operations or conditions have been written with some or all of the above 3.


code from the chapter

Do you want to see all the CODE I typed for the Truth Table?


what is next?

you now know

how to make a Python test driven development environment manually * what causes AssertionError? * how to make functions * what causes AttributeError * how to pass values from tests to functions * what is None and NOT None * what is True and False in Python * how to write programs that make decisions

Would you like to test projects that use the Truth Table?


rate pumping python

If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too.