-
Notifications
You must be signed in to change notification settings - Fork 1
/
bool.py
59 lines (43 loc) · 1.06 KB
/
bool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Fls():
def __init__(self):
pass
def vrednost(self, v):
return False
class Tru():
def __init__(self):
pass
def vrednost(self, v):
return True
class Var():
def __init__(self, ime):
self.ime = ime
def vrednost(self, v):
return v[self.ime]
class Not():
def __init__(self, p):
self.formula = p
def vrednost(self, v):
return not (self.formula.vrednost(v))
class And():
def __init__(self, ps):
self.formule = ps
def vrednost(self, v):
b = True
for p in self.formule:
b = b and p.vrednost(v)
if not b: break
return b
class Or():
def __init__(self, ps):
self.formule = ps
def vrednost(self, v):
b = False
for p in self.formule:
b = b or p.vrednost(v)
if b: break
return b
# Primer
moja_formula = And([Var("p"), Not(Var("p"))])
# Valuacija: prireditev vrednosti True/False spremenljivkam
v = { "p" : True, "q" : False }
print (moja_formula.vrednost(v))