Aktualizovat u8/program.py

This commit is contained in:
Oleksandr Mateshchuk 2026-11-03 13:37:04 +00:00
parent ac333aaa6f
commit 727452449e

View File

@ -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
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":