From ac333aaa6fb532bba90994209228e26e90555114 Mon Sep 17 00:00:00 2001 From: Oleksandr Mateshchuk Date: Tue, 3 Nov 2026 13:34:10 +0000 Subject: [PATCH] Aktualizovat u8/program.py --- u8/program.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/u8/program.py b/u8/program.py index 62b1d9a..ee2719b 100644 --- a/u8/program.py +++ b/u8/program.py @@ -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: - line = input() + 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): - print("Chybna databaza") - return + 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")