fix3u8
This commit is contained in:
parent
3d600bebb1
commit
bc6e595227
@ -1,5 +1,42 @@
|
||||
import sys
|
||||
|
||||
def main():
|
||||
print("Expert zo zoo to vie.")
|
||||
tree_lines = read_tree_lines()
|
||||
if not controla_batabaz(tree_lines):
|
||||
return
|
||||
q = pocet_otazok(tree_lines)
|
||||
a = pocet_odpovedi(tree_lines)
|
||||
tree = build_tree(tree_lines)
|
||||
print("Pocet otazok:", q)
|
||||
print("Pocet odpovedi:", a)
|
||||
print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.")
|
||||
koren = tree
|
||||
while koren is not None:
|
||||
if koren["otazka"].endswith("?"):
|
||||
print(koren["otazka"])
|
||||
odpoved = input().rstrip("\r")
|
||||
if odpoved == "a":
|
||||
koren = koren["a"]
|
||||
elif odpoved == "n":
|
||||
koren = koren["n"]
|
||||
else:
|
||||
print("Nerozumiem")
|
||||
return
|
||||
else:
|
||||
print(koren["otazka"])
|
||||
print("Koniec")
|
||||
break
|
||||
|
||||
def build_tree(tree_lines):
|
||||
if len(tree_lines) == 0:
|
||||
return None
|
||||
line = tree_lines.pop(0)
|
||||
node = {"otazka": line, "a": None, "n": None}
|
||||
if line.endswith("?"):
|
||||
node["a"] = build_tree(tree_lines)
|
||||
node["n"] = build_tree(tree_lines)
|
||||
return node
|
||||
|
||||
def pocet_otazok(tree_lines):
|
||||
a = 0
|
||||
@ -7,8 +44,6 @@ def pocet_otazok(tree_lines):
|
||||
if line.endswith("?"):
|
||||
a += 1
|
||||
return a
|
||||
|
||||
|
||||
def pocet_odpovedi(tree_lines):
|
||||
a = 0
|
||||
for line in tree_lines:
|
||||
@ -16,20 +51,6 @@ def pocet_odpovedi(tree_lines):
|
||||
a += 1
|
||||
return a
|
||||
|
||||
|
||||
def main():
|
||||
print("Expert zo zoo to vie.")
|
||||
tree_lines = read_tree_lines()
|
||||
if tree_lines is None or len(tree_lines) == 0:
|
||||
print("Chybna databaza")
|
||||
return
|
||||
print("Pocet otazok:", pocet_otazok(tree_lines))
|
||||
print("Pocet odpovedi:", pocet_odpovedi(tree_lines))
|
||||
print("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.")
|
||||
print(tree_lines[0])
|
||||
print("Koniec")
|
||||
|
||||
|
||||
def read_tree_lines():
|
||||
tree_lines = []
|
||||
text = input().rstrip("\r")
|
||||
@ -38,5 +59,14 @@ def read_tree_lines():
|
||||
text = input().rstrip("\r")
|
||||
return tree_lines
|
||||
|
||||
def controla_batabaz(tree_lines):
|
||||
if tree_lines is None or len(tree_lines) == 0:
|
||||
print("Chybna databaza")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user