summaryrefslogtreecommitdiff
path: root/python/problems/recursion/family_tree_name
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-10-06 14:40:16 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2016-10-06 14:41:03 +0200
commitd29fed213caccc7bf2f66ed7a11b94b4bbcac3d1 (patch)
tree04f96da9e5a4ea6572db9700907959eae295305b /python/problems/recursion/family_tree_name
parent969812724912512740dbf037940a9e6770df19ed (diff)
Python: add support for auxiliary code (like for Prolog)
Diffstat (limited to 'python/problems/recursion/family_tree_name')
-rw-r--r--python/problems/recursion/family_tree_name/common.py42
1 files changed, 5 insertions, 37 deletions
diff --git a/python/problems/recursion/family_tree_name/common.py b/python/problems/recursion/family_tree_name/common.py
index d924665..af549be 100644
--- a/python/problems/recursion/family_tree_name/common.py
+++ b/python/problems/recursion/family_tree_name/common.py
@@ -7,6 +7,7 @@ from server.hints import Hint
id = 20801
number = 1
visible = True
+facts = 'family_tree'
solution = '''\
def printnames(name):
@@ -19,40 +20,7 @@ hint_type = {
'final_hint': Hint('final_hint')
}
-precode = """
-children = {
- "Adam": ["Matjaž", "Cilka", "Daniel", "Erik"],
- "Aleksander": [],
- "Alenka": [],
- "Barbara": [],
- "Cilka": [],
- "Daniel": ["Elizabeta", "Hans"],
- "Erik": [],
- "Elizabeta": ["Ludvik", "Jurij", "Barbara", "Herman", "Mihael"],
- "Franc": [],
- "Herman": ["Margareta"],
- "Hans": [],
- "Jožef": ["Alenka", "Aleksander", "Petra"],
- "Jurij": ["Franc", "Jožef"],
- "Ludvik": [],
- "Margareta": [],
- "Matjaž": ["Viljem"],
- "Mihael": [],
- "Petra": [],
- "Tadeja": [],
- "Viljem": ["Tadeja"],
-}
-
-age = {
- "Adam": 111, "Matjaž": 90, "Cilka": 88, "Daniel": 85, "Erik": 83,
- "Viljem": 58, "Tadeja": 20, "Elizabeta": 67, "Hans": 64, "Ludvik": 50,
- "Jurij": 49, "Barbara": 45, "Herman": 39, "Mihael": 32, "Franc": 30,
- "Jožef": 29, "Margareta": 10, "Alenka": 5, "Aleksander": 7, "Petra": 9
-}"""
-
-def test(python, code):
- code = precode + "\n" + code
-
+def test(python, code, aux_code=''):
func_name = 'printnames'
tokens = get_tokens(code)
if not has_token_sequence(tokens, ['def', func_name]):
@@ -71,7 +39,7 @@ def test(python, code):
for l in in_out]
test_out = [l[1] for l in in_out]
- answers = python(code=code, inputs=test_in, timeout=1.0)
+ answers = python(code=aux_code+code, inputs=test_in, timeout=1.0)
n_correct = 0
tin, tout = None, None
for i, (ans, to) in enumerate(zip(answers, test_out)):
@@ -92,11 +60,11 @@ def test(python, code):
return passed, hints
-def hint(python, code):
+def hint(python, code, aux_code=''):
tokens = get_tokens(code)
# run one test first to see if there are any exceptions
- answer = python(code=code, inputs=[(None, None)], timeout=1.0)
+ answer = python(code=aux_code+code, inputs=[(None, None)], timeout=1.0)
exc = get_exception_desc(answer[0][3])
if exc: return exc