Aktualizovat u8/program.py

This commit is contained in:
Oleksandr Mateshchuk 2026-11-03 13:34:10 +00:00
parent 0cbb03de46
commit ac333aaa6f

View File

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