Python.use(better) #真理値表: step07 -- def implication(self):
‖記事一覧‖ Python.use(better)《Python3.1》
def implication(self):
《著》森こねこ、小粒ちゃん+∞《監修》小泉ひよ子とタマゴ倶楽部
第0版♪2001/03/02 ● 第1版♪2003/05/25 ● 第2版♪2004/06/01 ● 第3版♪2009/02/28
課題を作成する過程を通して「論理演算/文字列処理」の理解を深めます。
※ Python1.5 で作成した例題を、Python3.1 で再構成しました。
事例:コードの解説
class TruthTable(object):
...
def implication(self):
self.op = "=>"
B = self.boolean
self.table = [not b1 or b2
for b1 in B for b2 in B]
return self
## ----------------------------------------
local = locals()
ex_TruthTable2(local)
■ #1: メソッド
def implication(self): self.op = "=>" B = self.boolean self.table = [not b1 or b2 for b1 in B for b2 in B] return self
メソッド implication は、含意 implication を表わす、真理値表を作成します。
- 否定 not と論理和 or を利用して、再定義できます。
事例:モジュールを起動する
■ 全項目を確認する
全ステップの「項目」を確認するには、関数 do を利用します。
$ python -i TruthTable.py >>> do() 0: step00 -- class TruthTable(object): 1: step01 -- def __init__(self): 2: step02 -- def __iter__(self): 3: step03 -- def __repr__(self): 4: step04 -- def _body(self): 5: step05 -- def op_and(self): 6: step06 -- def operator(self, op): 7: step07 -- def implication(self): >>>
■ 各項目を実行する
各ステップの「動作」を確認するには、関数 do に実引数を指定します。
>>> do(7) >>> # -------------------------------------------------- step07 >>> t = TruthTable(); t p | q | p _ q
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
クラス ASCII のインスタンス a が生成されます。
《余録》テストケース
def ex_TruthTable2(local): #@:
ex_TruthTable1(local)
source = '''
t.operator("&")
t.operator("|")
t.operator("^")
t.operator("==")
t.operator("!=")
t.implication()
'''.split("\n")
do_it(source, local)
》こちらに移動中です《
↑TOP