diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/problems/introduction/fast_fingers_2/common.py | 23 | ||||
-rw-r--r-- | python/problems/introduction/fast_fingers_2/sl.py | 15 |
2 files changed, 27 insertions, 11 deletions
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': ['''\ -<p><b>Odlično!</b> Za konec pa še zanimivost. -Pri tej nalogi stavka <code>if</code> niti ne potrebujemo, saj bi lahko napisali le:</p> +<p>Odlično, program je pravilen! <br> +Za konec pa še zanimivost. Pri tej nalogi stavka <code>if</code> niti ne potrebujemo, saj bi lahko napisali le:</p> <pre> print(a*b == c) </pre> -<p>kar bi izpisalo rezultat tega izraza. Poskusi!</p>'''] +<p>kar bi izpisalo rezultat tega izraza. Poskusi!</p>'''], + 'final_hint_noif': ['''\ +<p>Odlično, program je pravilen! </p>'''], + + 'problematic_test_case': [ + '''\ +<p>Program ne deluje pravilno! <br> +Primer množenja: [%=mult%] <br> +Če vnesemo: [%=testin%], <br> +bi moral izpisati: [%=testout%].</p>'''] } |