From 727452449e549855f1f356235acefe2cc00d53e5 Mon Sep 17 00:00:00 2001 From: Oleksandr Mateshchuk Date: Tue, 3 Nov 2026 13:37:04 +0000 Subject: [PATCH] Aktualizovat u8/program.py --- u8/program.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/u8/program.py b/u8/program.py index ee2719b..f06ee98 100644 --- a/u8/program.py +++ b/u8/program.py @@ -1,3 +1,4 @@ +import sys class Node: def __init__(self, text): @@ -5,8 +6,9 @@ class Node: self.yes = None self.no = None - def create_tree(lines, index, counts): + if index[0] >= len(lines): + raise ValueError node = Node(lines[index[0]]) index[0] += 1 @@ -22,35 +24,29 @@ def create_tree(lines, index, counts): def main(): print("Expert zo zoo to vie.") - lines = [] while True: - try: - line = input() - except EOFError: + line = sys.stdin.readline() + if line == "": print("Chybna databaza") return - + line = line.rstrip("\r\n") if line == "": break - lines.append(line) - if len(lines) == 0: print("Chybna databaza") return - counts = [0, 0] index = [0] try: root = create_tree(lines, index, counts) - except (IndexError, RecursionError): - print("Chybna databaza") - return + if index[0] != len(lines): + raise ValueError - if index[0] != len(lines): + except (ValueError, RecursionError): print("Chybna databaza") return @@ -62,16 +58,15 @@ def main(): while True: print(current.text) - if not current.text.endswith("?"): break - try: - answer = input() - except EOFError: + answer = sys.stdin.readline() + if answer == "": print("Koniec vstupu") return + answer = answer.rstrip("\r\n") if answer == "a": current = current.yes elif answer == "n":