truth table: test_truth_table_tests
requirements
how to get back to the automated tests
If your tests stopped after the previous chapter, heres’s how to get back to the tests
Make sure you are in the
pumping_pythonfolder with pwd in the terminalpwdif the terminal shows anything other than
.../pumping_pythonyou need to change directory to the
pumping_pythonfolderOnce in the
pumping_pythondirectory, change directory to the projectcd truth_tablethe terminal shows
.../pumping_python/truth_tableactivate the Virtual Environment
source .venv/bin/activateon Windows without Windows Subsystem for Linux use
.venv/scripts/activate.ps1instead ofsource .venv/bin/activate.venv/scripts/activate.ps1when the Virtual Environment is activated, the terminal shows
(.venv) .../pumping_python/truth_tablerun the tests
pytest-watch
I want to write a program that makes the tests in test_truth_table.py pass without looking at them
RED: make it fail
I close
test_truth_table.pythen delete everything in
truth_table.py, the terminal shows 20 failures, I start with the last oneAttributeError: module 'src.truth_table' has no attribute 'tautology'
GREEN: make it pass
I add the name to
truth_table.py1tautologyNameError: name 'tautology' is not definedI point the name to None
1tautology = NoneTypeError: 'NoneType' object is not callableI make
tautologya function1def tautology(): 2 return NoneTypeError: tautology() takes 0 positional arguments but 2 were givenI add names in parentheses for the function to take input arguments
1def tautology(first_input, second_input): 2 return Nonethe terminal shows AssertionError
AssertionError: None is not trueI change None to True in the return statement
1def tautology(first_input, second_input): 2 return Truethe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'project_second'I add the function using the solution I just used for
tautology1def tautology(first_input, second_input): 2 return True 3 4 5def project_second(first_input, second_input): 6 return Truethe terminal shows AssertionError
AssertionError: True is not falseI change the return statement
5def project_second(first_input, second_input): 6 return Falsethe terminal shows AssertionError
AssertionError: False is not trueThe expectation of the test changes. I want to see the difference between the inputs and the expected output
5def project_second(first_input, second_input): 6 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, False) is not falsesecond_inputis False, I removefirst_inputfrom the return statement5def project_second(first_input, second_input): 6 return second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'project_first'I add a function for it
5def project_second(first_input, second_input): 6 return second_input 7 8 9def project_first(first_input, second_input): 10 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, True) is not falsefirst_inputis FalseI remove
second_inputfrom the return statement9def project_first(first_input, second_input): 10 return first_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'negate_second'I add a function for
negate_second9def project_first(first_input, second_input): 10 return first_input 11 12 13def negate_second(first_input, second_input): 14 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement to
negate_second13def negate_second(first_input, second_input): 14 if (first_input, second_input) == (True, True): return False 15 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add another if statement
13def negate_second(first_input, second_input): 14 if (first_input, second_input) == (True, True): return False 15 if (first_input, second_input) == (False, True): return False 16 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'negate_first'I add a function definition for it
13def negate_second(first_input, second_input): 14 if (first_input, second_input) == (True, True): return False 15 if (first_input, second_input) == (False, True): return False 16 return first_input, second_input 17 18 19def negate_first(first_input, second_input): 20 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, True)I add an if statement
19def negate_first(first_input, second_input): 20 if (first_input, second_input) == (True, True): return False 21 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add an if statement
19def negate_first(first_input, second_input): 20 if (first_input, second_input) == (True, True): return False 21 if (first_input, second_input) == (True, False): return False 22 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'material_non_implication'I add a function for
material_non_implication21 if (first_input, second_input) == (True, False): return False 22 return first_input, second_input 23 24 25def material_non_implication(first_input, second_input): 26 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
25def material_non_implication(first_input, second_input): 26 if (first_input, second_input) == (True, True): return False 27 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add another if statement
25def material_non_implication(first_input, second_input): 26 if (first_input, second_input) == (True, True): return False 27 if (first_input, second_input) == (False, True): return False 28 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add an if statement for it
25def material_non_implication(first_input, second_input): 26 if (first_input, second_input) == (True, True): return False 27 if (first_input, second_input) == (False, True): return False 28 if (first_input, second_input) == (False, False): return False 29 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'material_implication'I add a function for
material_implication28 if (first_input, second_input) == (False, False): return False 29 return first_input, second_input 30 31 32def material_implication(first_input, second_input): 33 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add an if statement
32def material_implication(first_input, second_input): 33 if (first_input, second_input) == (True, False): return False 34 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_nor'I add a function for
logical_nor33 if (first_input, second_input) == (True, False): return False 34 return first_input, second_input 35 36 37def logical_nor(first_input, second_input): 38 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
37def logical_nor(first_input, second_input): 38 if (first_input, second_input) == (True, True): return False 39 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add another if statement
37def logical_nor(first_input, second_input): 38 if (first_input, second_input) == (True, True): return False 39 if (first_input, second_input) == (True, False): return False 40 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add an if statement
37def logical_nor(first_input, second_input): 38 if (first_input, second_input) == (True, True): return False 39 if (first_input, second_input) == (True, False): return False 40 if (first_input, second_input) == (False, True): return False 41 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_nand'. Did you mean: 'logical_nor'?I add a function for
logical_nand40 if (first_input, second_input) == (False, True): return False 41 return first_input, second_input 42 43 44def logical_nand(first_input, second_input): 45 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
44def logical_nand(first_input, second_input): 45 if (first_input, second_input) == (True, True): return False 46 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_equality'I add the function
45 if (first_input, second_input) == (True, True): return False 46 return first_input, second_input 47 48 49def logical_equality(first_input, second_input): 50 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add an if statement
49def logical_equality(first_input, second_input): 50 if (first_input, second_input) == (True, False): return False 51 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add another if statement
49def logical_equality(first_input, second_input): 50 if (first_input, second_input) == (True, False): return False 51 if (first_input, second_input) == (False, True): return False 52 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_disjunction'I add a function for
logical_disjunction51 if (first_input, second_input) == (False, True): return False 52 return first_input, second_input 53 54 55def logical_disjunction(first_input, second_input): 56 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add an if statement
55def logical_disjunction(first_input, second_input): 56 if (first_input, second_input) == (False, False): return False 57 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_conjunction'. Did you mean: 'logical_disjunction'?I add a function for
logical_conjunction56 if (first_input, second_input) == (False, False): return False 57 return first_input, second_input 58 59 60def logical_conjunction(first_input, second_input): 61 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add an if statement
60def logical_conjunction(first_input, second_input): 61 if (first_input, second_input) == (True, False): return False 62 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add an if statement
60def logical_conjunction(first_input, second_input): 61 if (first_input, second_input) == (True, False): return False 62 if (first_input, second_input) == (False, True): return False 63 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add another if statement
60def logical_conjunction(first_input, second_input): 61 if (first_input, second_input) == (True, False): return False 62 if (first_input, second_input) == (False, True): return False 63 if (first_input, second_input) == (False, False): return False 64 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'exclusive_disjunction'I add a function for
exclusive_disjunction63 if (first_input, second_input) == (False, False): return False 64 return first_input, second_input 65 66 67def exclusive_disjunction(first_input, second_input): 68 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
67def exclusive_disjunction(first_input, second_input): 68 if (first_input, second_input) == (True, True): return False 69 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add another if statement
67def exclusive_disjunction(first_input, second_input): 68 if (first_input, second_input) == (True, True): return False 69 if (first_input, second_input) == (False, False): return False 70 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'converse_non_implication'. Did you mean: 'material_non_implication'?I add a definition for the
converse_non_implicationfunction69 if (first_input, second_input) == (False, False): return False 70 return first_input, second_input 71 72 73def converse_non_implication(first_input, second_input): 74 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
73def converse_non_implication(first_input, second_input): 74 if (first_input, second_input) == (True, True): return False 75 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add another if statement
73def converse_non_implication(first_input, second_input): 74 if (first_input, second_input) == (True, True): return False 75 if (first_input, second_input) == (True, False): return False 76 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add an if statement
73def converse_non_implication(first_input, second_input): 74 if (first_input, second_input) == (True, True): return False 75 if (first_input, second_input) == (True, False): return False 76 if (first_input, second_input) == (False, False): return False 77 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'converse_implication'. Did you mean: 'converse_non_implication'?I add the function for
converse_implication76 if (first_input, second_input) == (False, False): return False 77 return first_input, second_input 78 79 80def converse_implication(first_input, second_input): 81 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add an if statement
80def converse_implication(first_input, second_input): 81 if (first_input, second_input) == (False, True): return False 82 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'contradiction'I add a function for
contradiction81 if (first_input, second_input) == (False, True): return False 82 return first_input, second_input 83 84 85def contradiction(first_input, second_input): 86 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, True) is not falseI add an if statement
85def contradiction(first_input, second_input): 86 if (first_input, second_input) == (True, True): return False 87 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (True, False) is not falseI add another if statement
85def contradiction(first_input, second_input): 86 if (first_input, second_input) == (True, True): return False 87 if (first_input, second_input) == (True, False): return False 88 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, True) is not falseI add another if statement
85def contradiction(first_input, second_input): 86 if (first_input, second_input) == (True, True): return False 87 if (first_input, second_input) == (True, False): return False 88 if (first_input, second_input) == (False, True): return False 89 return first_input, second_inputthe terminal shows AssertionError
AssertionError: (False, False) is not falseI add an if statement
85def contradiction(first_input, second_input): 86 if (first_input, second_input) == (True, True): return False 87 if (first_input, second_input) == (True, False): return False 88 if (first_input, second_input) == (False, True): return False 89 if (first_input, second_input) == (False, False): return False 90 return first_input, second_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_negation'. Did you mean: 'logical_conjunction'?I add a function for
logical_negation89 if (first_input, second_input) == (False, False): return False 90 return first_input, second_input 91 92 93def logical_negation(first_input, second_input): 94 return first_input, second_inputTypeError: logical_negation() missing 1 required positional argument: 'second_input'I remove
second_inputfrom the parentheses, to make the function take only 1 input,93def logical_negation(first_input): 94 return first_inputthe terminal shows AssertionError
AssertionError: True is not falseI add “not” to the return statement
93def logical_negation(first_input): 94 return not first_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_identity'. Did you mean: 'logical_equality'?I add a function for
logical_identity93def logical_negation(first_input): 94 return not first_input 95 96 97def logical_identity(the_input): 98 return not the_inputthe terminal shows AssertionError
AssertionError: False is not trueI remove “not” from the return statement
97def logical_identity(the_input): 98 return the_inputthe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_true'. Did you mean: 'logical_nand'?I add a function for
logical_true97def logical_identity(the_input): 98 return the_input 99 100 101def logical_true(the_input): 102 return the_inputTypeError: logical_true() missing 1 required positional argument: 'x'I remove
first_inputfrom the parentheses, this function does not take input, I change the return statement101def logical_true(): 102 return Nonethe terminal shows AssertionError
AssertionError: None is not trueI change None to True in the return statement
101def logical_true(): 102 return Truethe terminal shows AttributeError
AttributeError: module 'src.truth_table' has no attribute 'logical_false'. Did you mean: 'logical_nand'?I add a function for
logical_false101def logical_true(): 102 return True 103 104 105def logical_false(): 106 return Falsethe terminal shows green! All tests are passing and the world is a better place than when I started.
REFACTOR: make it better
I can refactor the functions I have, to make them simpler since all the tests are passing
logical_false, logical_true, logical_identity and logical_negation are already simple
I change the name of the input in Logical Negation
Tip
In Visual Studio Code I can change everywhere a name is by using
93def logical_negation(the_input): 94 return not the_inputcontradiction returns False in 4 cases, with 2 inputs there are only 4 cases. I add a return statement
85def contradiction(first_input, second_input): 86 return False 87 if (first_input, second_input) == (True, True): return False 88 if (first_input, second_input) == (True, False): return False 89 if (first_input, second_input) == (False, True): return False 90 if (first_input, second_input) == (False, False): return False 91 return first_input, second_inputthe test is still green. I remove the other lines in the function
85def contradiction(first_input, second_input): 86 return False 87 88 89def logical_negation(x): 90 return not first_inputconverse_implication returns False in only one case, I return the logical negation of the if statement, for the 3 cases that return True
80def converse_implication(first_input, second_input): 81 return (first_input, second_input) != (False, True) 82 if (first_input, second_input) == (False, True): return False 83 return first_input, second_inputstill green. I remove the other statements
80def converse_implication(first_input, second_input): 81 return (first_input, second_input) != (False, True) 82 83 84def contradiction(first_input, second_input): 85 return Falseconverse_non_implication has only one case that returns True, it is the missing case. I add a return statement for it
73def converse_non_implication(first_input, second_input): 74 return (first_input, second_input) == (False, True) 75 if (first_input, second_input) == (True, True): return False 76 if (first_input, second_input) == (True, False): return False 77 if (first_input, second_input) == (False, False): return False 78 return first_input, second_inputthe terminal still shows green and I remove the other lines
73def converse_non_implication(first_input, second_input): 74 return (first_input, second_input) == (False, True) 75 76 77def converse_implication(first_input, second_input): 78 return (first_input, second_input) != (False, True)exclusive_disjunction has two if statements. I put them together to make one if statement
67def exclusive_disjunction(first_input, second_input): 68 if ( 69 (first_input, second_input) == (True, True) 70 or 71 (first_input, second_input) == (False, False) 72 ): return False 73 if (first_input, second_input) == (True, True): return False 74 if (first_input, second_input) == (False, False): return False 75 return first_input, second_inputthe test is still green. I remove the other if statements then return the logical negation of the if statement
67def exclusive_disjunction(first_input, second_input): 68 return ( 69 (first_input, second_input) != (True, True) 70 and 71 (first_input, second_input) != (False, False) 72 ) 73 74 75def converse_non_implication(first_input, second_input): 76 return (first_input, second_input) == (False, True)the test is still green, I remove the other lines
67def exclusive_disjunction(first_input, second_input): 68 return (first_input, second_input) != (True, True) and return (first_input, second_input) != (False, False) 69 70 71def converse_non_implication(first_input, second_input): 72 return (first_input, second_input) == (False, True)logical_conjunction only has one case that returns True, it is the missing case. I add a return statement for it
60def logical_conjunction(first_input, second_input): 61 return (first_input, second_input) == (True, True) 62 if (first_input, second_input) == (True, False): return False 63 if (first_input, second_input) == (False, True): return False 64 if (first_input, second_input) == (False, False): return False 65 return first_input, second_inputstill green, I remove the other statements
60def logical_conjunction(first_input, second_input): 61 return (first_input, second_input) == (True, True) 62 63 64def exclusive_disjunction(first_input, second_input): 65 return (logical_disjunction only has one case that returns False, I add a return statement for the opposite of it which covers the other 3 cases
55def logical_disjunction(first_input, second_input): 56 return (first_input, second_input) != (False, False) 57 if (first_input, second_input) == (False, False): return False 58 return first_input, second_inputthe terminal still shows green. I remove the other lines
55def logical_disjunction(first_input, second_input): 56 return (first_input, second_input) != (False, False) 57 58 59def logical_conjunction(first_input, second_input): 60 return (first_input, second_input) == (True, True)logical_equality has two if statements. I use what I know from exclusive_disjunction to add a return statement
49def logical_equality(first_input, second_input): 50 return ( 51 (first_input, second_input) != (True, False) 52 and 53 (first_input, second_input) != (False, True) 54 ) 55 if (first_input, second_input) == (True, False): return False 56 if (first_input, second_input) == (False, True): return False 57 return first_input, second_inputthe terminal still shows green. I remove the other lines
49def logical_equality(first_input, second_input): 50 return ( 51 (first_input, second_input) != (True, False) 52 and 53 (first_input, second_input) != (False, True) 54 ) 55 56 57def logical_disjunction(first_input, second_input): 58 return (first_input, second_input) != (False, False)logical_nand only has one case that returns False, I add a return statement for its opposite which covers the other 3 cases
44def logical_nand(first_input, second_input): 45 return (first_input, second_input) != (True, True) 46 if (first_input, second_input) == (True, True): return False 47 return first_input, second_inputstill green. I remove the other lines
44def logical_nand(first_input, second_input): 45 return (first_input, second_input) != (True, True) 46 47 48def logical_equality(first_input, second_input): 49 return (logical_nor only has one case that returns True, I add a return statement for it
37def logical_nor(first_input, second_input): 38 return (first_input, second_input) == (False, False) 39 if (first_input, second_input) == (True, True): return False 40 if (first_input, second_input) == (True, False): return False 41 if (first_input, second_input) == (False, True): return False 42 return first_input, second_inputstill green, I remove the other statements
37def logical_nor(first_input, second_input): 38 return (first_input, second_input) == (False, False) 39 40 41def logical_nand(first_input, second_input): 42 return (first_input, second_input) != (True, True)material_implication has only one case that returns False, I add a return statement for the other 3
32def material_implication(first_input, second_input): 33 return (first_input, second_input) != (True, False) 34 if (first_input, second_input) == (True, False): return False 35 return first_input, second_inputthe test is still green. I remove the other statements
32def material_implication(first_input, second_input): 33 return (first_input, second_input) != (True, False) 34 35 36def logical_nor(first_input, second_input): 37 return (first_input, second_input) == (False, False)material_non_implication has 3 cases that return False. I add a return statement for the missing case that returns True
25def material_non_implication(first_input, second_input): 26 return (first_input, second_input) == (True, False) 27 if (first_input, second_input) == (True, True): return False 28 if (first_input, second_input) == (False, True): return False 29 if (first_input, second_input) == (False, False): return False 30 return first_input, second_inputthe terminal still shows green. I remove the other statements
25def material_non_implication(first_input, second_input): 26 return (first_input, second_input) == (True, False) 27 28 29def material_implication(first_input, second_input): 30 return (first_input, second_input) != (True, False)first_inputis True in the 2 cases where negate_first returns False, I add an if statement for them19def negate_first(first_input, second_input): 20 if first_input == True: return False 21 if (first_input, second_input) == (True, True): return False 22 if (first_input, second_input) == (True, False): return False 23 return first_input, second_inputthe test is still green. I remove the other if statements, then add a simpler return statement
19def negate_first(first_input, second_input): 20 return first_input != True 21 if first_input == True: return False 22 return first_input, second_inputthe test is still green, I remove the other statements
19def negate_first(first_input, second_input): 20 return first_input != True 21 22 23def material_non_implication(first_input, second_input): 24 return (first_input, second_input) == (True, False)second_inputis True in the 2 cases where negate_second returns False. I add a return statement like the one from negate_first13def negate_second(first_input, second_input): 14 return second_input != True 15 if (first_input, second_input) == (True, True): return False 16 if (first_input, second_input) == (False, True): return False 17 return first_input, second_inputstill green. I remove the other statements
13def negate_second(first_input, second_input): 14 return second_input != True 15 16 17def negate_first(first_input, second_input): 18 return first_input != Trueproject_second, project_first and tautology are already simple
I change the return statement in negate_second to make it simpler
13def negate_second(first_input, second_input): 14 return not second_input == True 15 return second_input != Truewhen
not second_inputis True it means the return statement isTrue == Truewhich is a duplication. I remove the second part of the statement and the second return statement13def negate_second(first_input, second_input): 14 return not second_input 15 16 17def negate_first(first_input, second_input):the test is still green
I do the same thing with negate_first
17def negate_first(first_input, second_input): 18 return not first_input 19 return first_input != Truestill green. I remove the second return statement
17def negate_first(first_input, second_input): 18 return not first_input 19 20 21def material_non_implication(first_input, second_input):I use this with material_non_implication
21def material_non_implication(first_input, second_input): 22 return first_input and not second_input 23 return (first_input, second_input) == (True, False)the terminal shows all tests are still passing. I remove the second return statement
21def material_non_implication(first_input, second_input): 22 return first_input and not second_input 23 24 25def material_implication(first_input, second_input):I try it with material_implication
25def material_implication(first_input, second_input): 26 return not first_input and second_input 27 return (first_input, second_input) != (True, False)the terminal shows AssertionError
AssertionError: False is not trueNot good! I change “and” to “or”
25def material_implication(first_input, second_input): 26 return not first_input or second_input 27 return (first_input, second_input) != (True, False)the test is green again. Note to self - use “or” the next time I see
!=in these tests. I remove the other return statement25def material_implication(first_input, second_input): 26 return not first_input or second_input 27 28 29def logical_nor(first_input, second_input):I do the same thing with logical_nor
29def logical_nor(first_input, second_input): 30 return not first_input and not second_input 31 return (first_input, second_input) == (False, False)the test is still green. I remove the second return statement and change the first return statement in terms of “not” since it happens 2 times
29def logical_nor(first_input, second_input): 30 return (not first_input) (not or) (not second_input) 31 return not first_input and not second_inputthe terminal shows SyntaxError
SyntaxError: invalid syntaxI comment the line out then factor out “not”
29def logical_nor(first_input, second_input): 30 return not (first_input or second_input) 31 # return (not first_input) (not or) (not second_input) 32 return not first_input and not second_inputthe terminal still shows green. I remove the other statements
29def logical_nor(first_input, second_input): 30 return not (first_input or second_input) 31 32 33def logical_nand(first_input, second_input):I add a return statement to logical_nand
33def logical_nand(first_input, second_input): 34 return not first_input or not second_input 35 return (first_input, second_input) != (True, True)the test is still green, I remove the second return statement then factor out “not” in the first
33def logical_nand(first_input, second_input): 34 return not (first_input and second_input) 35 return not first_input or not second_inputstill green. I remove the other return statements
33def logical_nand(first_input, second_input): 34 return not (first_input and second_input) 35 36 37def logical_equality(first_input, second_input):I add a return statement to logical_equality
37def logical_equality(first_input, second_input): 38 return (not first_input or second_input) and (first_input or not second_input) 39 return ( 40 (first_input, second_input) != (True, False) 41 and 42 (first_input, second_input) != (False, True) 43 )the test is still green, I remove the other return statement
37def logical_equality(first_input, second_input): 38 return (not first_input or second_input) and (first_input or not second_input) 39 40 41def logical_disjunction(first_input, second_input):I do the same thing with logical_disjunction
41def logical_disjunction(first_input, second_input): 42 return first_input or second_input 43 return (first_input, second_input) != (False, False)still green. I remove the other return statement
41def logical_disjunction(first_input, second_input): 42 return first_input or second_input 43 44 45def logical_conjunction(first_input, second_input):on to logical_conjunction
45def logical_conjunction(first_input, second_input): 46 return first_input and second_input 47 return (first_input, second_input) == (True, True)the terminal still shows green. I remove the other return statement
45def logical_conjunction(first_input, second_input): 46 return first_input and second_input 47 48 49def exclusive_disjunction(first_input, second_input):I add a return statement to exclusive_disjunction
49def exclusive_disjunction(first_input, second_input): 50 return ( 51 (not first_input or not second_input) 52 and 53 (first_input or second_input) 54 ) 55 return ( 56 (first_input, second_input) != (True, True) 57 and 58 (first_input, second_input) != (False, False) 59 )still green. I remove the second return statement then factor out “not” from the first part of the statement
49def exclusive_disjunction(first_input, second_input): 50 return ( 51 not (first_input and second_input) 52 # (not first_input or not second_input) 53 and 54 (first_input or second_input) 55 )the test is still green. I remove the commented line
49def exclusive_disjunction(first_input, second_input): 50 return ( 51 not (first_input and second_input) 52 and 53 (first_input or second_input) 54 ) 55 56 57def converse_non_implication(first_input, second_input):I add a simpler return statement to converse_non_implication
57def converse_non_implication(first_input, second_input): 58 return not first_input and second_input 59 return (first_input, second_input) == (False, True)still green. I remove the other line
57def converse_non_implication(first_input, second_input): 58 return not first_input and second_input 59 60 61def converse_implication(first_input, second_input):time for converse_implication
61def converse_implication(first_input, second_input): 62 return first_input or not second_input 63 return (first_input, second_input) != (False, True)I remove the second return statement
61def converse_implication(first_input, second_input): 62 return first_input or not second_input 63 64 65def contradiction(first_input, second_input):
all the tests are still passing
close the project
I close the file(s) I had open in the editor(s)
I exit the tests in the terminal with Ctrl+C on the keyboard
I deactivate the virtual environment
deactivatethe terminal goes back to the command line,
(.venv)is no longer on the left side.../pumping_python/truth_tableI change directory to the parent of
truth_tablecd ..the terminal shows
.../pumping_pythonI am back in the
pumping_pythondirectory
review
I ran tests using booleans which can be True or False for the operations of the Truth Table from Mathematics
there are 2 nullary operations, they do not take input and always return the same thing, they are constant
Logical False always returns False
Logical True always returns True
there are 2 unary operations, they take one input
Logical Identity returns its input as output
Logical Negation returns the negation of its input as output
there are 16 binary operations, they each take 2 inputs, in this case I named the second input
second_inputand the first onefirst_input-
returns
first_input or not second_inputreturns False when
first_inputis False andsecond_inputis Trueis the opposite or Logical Negation of Converse NonImplication which only returns True when
first_inputis False andsecond_inputis True
-
returns
not first_input and second_inputreturns True when
first_inputis False andsecond_inputis Trueis the opposite or Logical Negation of Converse Implication which only returns False when
first_inputis False andsecond_inputis True
-
returns
first_input != second_inputreturns True when
first_inputandsecond_inputare NOT equalis the opposite or Logical Negation of Logical Equality which only returns True when the two inputs are equal
Logical Conjunction returns
returns
first_input and second_inputis the opposite or Logical Negation of Logical NAND which only returns False when the two inputs are True
-
returns
first_input or second_inputreturns True when
first_inputandsecond_inputare both Falseis the opposite or Logical Negation of Logical NOR which only returns True when the two inputs are False
-
returns
first_input == second_inputreturns True when
first_inputandsecond_inputare equalis the opposite or Logical Negation of Exclusive Disjunction (Exclusive OR) which only returns True when the two inputs are NOT equal
-
returns
not (first_input and second_input)returns False when
first_inputandsecond_inputare both Trueis the opposite or Logical Negation (not) of Logical Conjunction (and) which only returns True when the two inputs are True
-
returns
not (first_input or second_input)returns True when
first_inputandsecond_inputare both Falseis the opposite or Logical Negation of Logical Disjunction which only returns False when the two inputs are False
-
returns
not first_input or second_inputreturns False when
first_inputis True andsecond_inputis Falseis the opposite or Logical Negation of Material NonImplication which returns True only when
first_inputis True andsecond_inputis False
-
returns
first_input and not second_inputreturns True when
first_inputis False andsecond_inputis Trueis the opposite or Logical Negation of Material or Logical Implication which only returns False when
first_inputis True andsecond_inputis False
-
returns
not first_inputis the opposite or Logical Negation of Project First which only returns True when
first_inputis True
-
returns
not second_inputis the opposite or Logical Negation of Project Second which only returns True when
second_inputis True
-
returns
first_inputis the opposite or Logical Negation of Negate First which only returns True when
first_inputis False
-
returns
second_inputis the opposite or Logical Negation of Negate Second which only returns True when
second_inputis False
-
always returns True
is the opposite or Logical Negation of Contradiction which always returns False
and
Logical Disjunction is “or”
Logical Conjunction is “and”
Logical Negation is “not”
All the logic statements 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