diff --git a/u8/program.py b/u8/program.py index b5e019a..62b1d9a 100644 --- a/u8/program.py +++ b/u8/program.py @@ -8,6 +8,7 @@ class Node: def create_tree(lines, index, counts): text = lines[index[0]] index[0] += 1 + node = Node(text) if text.endswith("?"): @@ -20,12 +21,11 @@ def create_tree(lines, index, counts): return node - - def main(): + print("Expert zo zoo to vie.") + print() lines = [] - print("Expert zo zoo to vie.") while True: line = input() if line == "": @@ -38,13 +38,22 @@ def main(): counts = [0, 0] index = [0] - root = create_tree(lines, index, counts) + try: + root = create_tree(lines, index, counts) + if index[0] != len(lines): + print("Chybna databaza") + return + + except (IndexError, EOFError): + 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("?"): @@ -54,6 +63,7 @@ def main(): except EOFError: print("Koniec vstupu") return + if answer == "a": current = current.yes elif answer == "n":