Aktualizovat u8/program.py
This commit is contained in:
parent
ac333aaa6f
commit
727452449e
@ -1,3 +1,4 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, text):
|
def __init__(self, text):
|
||||||
@ -5,8 +6,9 @@ class Node:
|
|||||||
self.yes = None
|
self.yes = None
|
||||||
self.no = None
|
self.no = None
|
||||||
|
|
||||||
|
|
||||||
def create_tree(lines, index, counts):
|
def create_tree(lines, index, counts):
|
||||||
|
if index[0] >= len(lines):
|
||||||
|
raise ValueError
|
||||||
node = Node(lines[index[0]])
|
node = Node(lines[index[0]])
|
||||||
index[0] += 1
|
index[0] += 1
|
||||||
|
|
||||||
@ -22,35 +24,29 @@ def create_tree(lines, index, counts):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Expert zo zoo to vie.")
|
print("Expert zo zoo to vie.")
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
line = sys.stdin.readline()
|
||||||
line = input()
|
if line == "":
|
||||||
except EOFError:
|
|
||||||
print("Chybna databaza")
|
print("Chybna databaza")
|
||||||
return
|
return
|
||||||
|
line = line.rstrip("\r\n")
|
||||||
if line == "":
|
if line == "":
|
||||||
break
|
break
|
||||||
|
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
|
|
||||||
if len(lines) == 0:
|
if len(lines) == 0:
|
||||||
print("Chybna databaza")
|
print("Chybna databaza")
|
||||||
return
|
return
|
||||||
|
|
||||||
counts = [0, 0]
|
counts = [0, 0]
|
||||||
index = [0]
|
index = [0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
root = create_tree(lines, index, counts)
|
root = create_tree(lines, index, counts)
|
||||||
except (IndexError, RecursionError):
|
|
||||||
print("Chybna databaza")
|
|
||||||
return
|
|
||||||
|
|
||||||
if index[0] != len(lines):
|
if index[0] != len(lines):
|
||||||
|
raise ValueError
|
||||||
|
|
||||||
|
except (ValueError, RecursionError):
|
||||||
print("Chybna databaza")
|
print("Chybna databaza")
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -62,16 +58,15 @@ def main():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
print(current.text)
|
print(current.text)
|
||||||
|
|
||||||
if not current.text.endswith("?"):
|
if not current.text.endswith("?"):
|
||||||
break
|
break
|
||||||
|
|
||||||
try:
|
answer = sys.stdin.readline()
|
||||||
answer = input()
|
if answer == "":
|
||||||
except EOFError:
|
|
||||||
print("Koniec vstupu")
|
print("Koniec vstupu")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
answer = answer.rstrip("\r\n")
|
||||||
if answer == "a":
|
if answer == "a":
|
||||||
current = current.yes
|
current = current.yes
|
||||||
elif answer == "n":
|
elif answer == "n":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user