Aktualizovat u8/program.py
This commit is contained in:
parent
0cbb03de46
commit
ac333aaa6f
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, text):
|
def __init__(self, text):
|
||||||
self.text = text
|
self.text = text
|
||||||
@ -6,12 +7,10 @@ class Node:
|
|||||||
|
|
||||||
|
|
||||||
def create_tree(lines, index, counts):
|
def create_tree(lines, index, counts):
|
||||||
text = lines[index[0]]
|
node = Node(lines[index[0]])
|
||||||
index[0] += 1
|
index[0] += 1
|
||||||
|
|
||||||
node = Node(text)
|
if node.text.endswith("?"):
|
||||||
|
|
||||||
if text.endswith("?"):
|
|
||||||
counts[0] += 1
|
counts[0] += 1
|
||||||
node.yes = create_tree(lines, index, counts)
|
node.yes = create_tree(lines, index, counts)
|
||||||
node.no = create_tree(lines, index, counts)
|
node.no = create_tree(lines, index, counts)
|
||||||
@ -23,16 +22,22 @@ def create_tree(lines, index, counts):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Expert zo zoo to vie.")
|
print("Expert zo zoo to vie.")
|
||||||
print()
|
|
||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = input()
|
try:
|
||||||
|
line = input()
|
||||||
|
except EOFError:
|
||||||
|
print("Chybna databaza")
|
||||||
|
return
|
||||||
|
|
||||||
if line == "":
|
if line == "":
|
||||||
break
|
break
|
||||||
|
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
|
|
||||||
if not lines:
|
if len(lines) == 0:
|
||||||
print("Chybna databaza")
|
print("Chybna databaza")
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -41,23 +46,26 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
root = create_tree(lines, index, counts)
|
root = create_tree(lines, index, counts)
|
||||||
if index[0] != len(lines):
|
except (IndexError, RecursionError):
|
||||||
print("Chybna databaza")
|
print("Chybna databaza")
|
||||||
return
|
return
|
||||||
|
|
||||||
except (IndexError, EOFError):
|
if index[0] != len(lines):
|
||||||
print("Chybna databaza")
|
print("Chybna databaza")
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f"Pocet otazok: {counts[0]}")
|
print(f"Pocet otazok: {counts[0]}")
|
||||||
print(f"Pocet odpovedi: {counts[1]}")
|
print(f"Pocet odpovedi: {counts[1]}")
|
||||||
print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.")
|
print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.")
|
||||||
print()
|
|
||||||
|
|
||||||
current = root
|
current = root
|
||||||
|
|
||||||
while current.text.endswith("?"):
|
while True:
|
||||||
print(current.text)
|
print(current.text)
|
||||||
|
|
||||||
|
if not current.text.endswith("?"):
|
||||||
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
answer = input()
|
answer = input()
|
||||||
except EOFError:
|
except EOFError:
|
||||||
@ -72,7 +80,6 @@ def main():
|
|||||||
print("Nerozumiem")
|
print("Nerozumiem")
|
||||||
return
|
return
|
||||||
|
|
||||||
print(current.text)
|
|
||||||
print("Koniec")
|
print("Koniec")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user