import sys class Node: def __init__(self, text): self.text = text self.left = None self.right = None def is_question(self): return self.text.endswith("?") def read_line(): line = sys.stdin.readline() if line == "": return None if line.endswith("\n"): line = line[:-1] if line.endswith("\r"): line = line[:-1] return line class Tree: def __init__(self): self.root = None self.question_count = 0 self.answer_count = 0 def load(self): pending_questions = [] while True: text = read_line() if text is None: return False if text == "": if self.root is None or pending_questions: return False return True node = Node(text) if self.root is None: self.root = node else: if not pending_questions: return False parent = pending_questions[-1] if parent.left is None: parent.left = node else: parent.right = node pending_questions.pop() if node.is_question(): self.question_count += 1 pending_questions.append(node) else: self.answer_count += 1 def find_animal(self): current_node = self.root while True: print(current_node.text) if not current_node.is_question(): print("Koniec") return choice = read_line() if choice is None: print("Koniec vstupu") return if choice == "a": current_node = current_node.left elif choice == "n": current_node = current_node.right else: print("Nerozumiem") return def main(): print("Expert zo zoo to vie.") tree = Tree() if not tree.load(): print("Chybna databaza") return print(f"Pocet otazok: {tree.question_count}") print(f"Pocet odpovedi: {tree.answer_count}") print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.") tree.find_animal() if __name__ == "__main__": main()