From 609daf7798f98b0359bb188eb3a83690e93ace7f Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 7 Oct 2015 10:55:06 +0200 Subject: Added final hint to Fast Fingers 2. --- .../problems/introduction/fast_fingers_2/common.py | 23 ++++++++++++++-------- python/problems/introduction/fast_fingers_2/sl.py | 15 +++++++++++--- 2 files changed, 27 insertions(+), 11 deletions(-) (limited to 'python') diff --git a/python/problems/introduction/fast_fingers_2/common.py b/python/problems/introduction/fast_fingers_2/common.py index 6261d92..af4439c 100644 --- a/python/problems/introduction/fast_fingers_2/common.py +++ b/python/problems/introduction/fast_fingers_2/common.py @@ -32,7 +32,8 @@ random.randint = lambda x, y: {} hint_type = { 'random': Hint('random'), 'if_clause': Hint('if_clause'), - 'final_hint': Hint('final_hint') + 'final_hint': Hint('final_hint'), + 'final_hint_noif': Hint('final_hint_noif') } def test(python, code): @@ -62,21 +63,25 @@ def test(python, code): answers = python(code=tcode, inputs=[(None, t[1])], timeout=1.0) output = answers[0][1] - print ("out", output) - print (answers) if str(test_out[ti]) in output and str(not test_out[ti]) not in output: n_correct += 1 else: - tin = '{t[0]}*{t[0]}={t[1]}'.format(t=t) + tin = '{t[1]}'.format(t=t) tout = test_out[ti] + mult = '{t[0]}*{t[0]}'.format(t=t) passed = n_correct == len(test) hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test)}}] if tin: - hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + hints.append({'id': 'problematic_test_case', 'args': {'mult' : mult, 'testin': str(tin), 'testout': str(tout)}}) else: - hints.append({'id': 'final_hint'}) + tokens = get_tokens(code) + if has_token_sequence(tokens, ['if']): + hints.append({'id': 'final_hint'}) + else: + hints.append({'id': 'final_hint_noif'}) + return passed, hints def hint(python, code): @@ -88,7 +93,8 @@ def hint(python, code): exc = answer[0][3] exc_hint = get_exception_desc(answer[0][3]) # if have an exception! - return exc_hint + if exc_hint: + return exc_hint # First: if student does not import random, tell him about that module if not has_token_sequence(tokens, ['random']) or \ @@ -97,7 +103,8 @@ def hint(python, code): # Student will have to test whether result is correct or not - if not has_token_sequence(tokens, ['if']): + if not has_token_sequence(tokens, ['if']) and \ + not has_token_sequence(tokens, ['==']): return [{'id' : 'if_clause'}] return None diff --git a/python/problems/introduction/fast_fingers_2/sl.py b/python/problems/introduction/fast_fingers_2/sl.py index 6472442..125bd24 100644 --- a/python/problems/introduction/fast_fingers_2/sl.py +++ b/python/problems/introduction/fast_fingers_2/sl.py @@ -66,11 +66,20 @@ hint = { 'if_clause': if_clause, 'final_hint': ['''\ -

Odlično! Za konec pa še zanimivost. -Pri tej nalogi stavka if niti ne potrebujemo, saj bi lahko napisali le:

+

Odlično, program je pravilen!
+Za konec pa še zanimivost. Pri tej nalogi stavka if niti ne potrebujemo, saj bi lahko napisali le:

 print(a*b == c)
 
-

kar bi izpisalo rezultat tega izraza. Poskusi!

'''] +

kar bi izpisalo rezultat tega izraza. Poskusi!

'''], + 'final_hint_noif': ['''\ +

Odlično, program je pravilen!

'''], + + 'problematic_test_case': [ + '''\ +

Program ne deluje pravilno!
+Primer množenja: [%=mult%]
+Če vnesemo: [%=testin%],
+bi moral izpisati: [%=testout%].

'''] } -- cgit v1.2.1