From 5aca8a1a9bcc539957e3eee339ea5b72e27e5c7f Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 16 Sep 2015 14:03:35 +0200 Subject: Added problems Fast Fingers and Fast Fingers 2. --- .../problems/introduction/fast_fingers/common.py | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 python/problems/introduction/fast_fingers/common.py (limited to 'python/problems/introduction/fast_fingers/common.py') diff --git a/python/problems/introduction/fast_fingers/common.py b/python/problems/introduction/fast_fingers/common.py new file mode 100644 index 0000000..3c1b138 --- /dev/null +++ b/python/problems/introduction/fast_fingers/common.py @@ -0,0 +1,61 @@ +# coding=utf-8 + +from python.util import has_token_sequence +from server.hints import Hint, HintSequence + +id = 190 +group = 'introduction' +number = 2 +visible = True + +solution = '''\ +from time import time +zacetek = time() +rezultat = float(input("Koliko je 7*6? ")) +konec = time() +cas = konec­zacetek +print ("Porabil si ", cas, "s.") +''' + +hint_type = { + 'plan': Hint('plan'), + 'name_error': HintSequence('name_error', 4), + 'type_error': HintSequence('name_error', 4), + 'error': HintSequence('error', 2), + 'time': Hint('time'), + 'time_diff': Hint('time_diff'), +} + +def test(python, code): + return 0, 0 + +def hint(python, code): + # run one test first to see if there are any exceptions + test_in = [(None, '5\n')] + answer = python(code=code, inputs=test_in, timeout=2.0) + exc = answer[0][3] + # if have an exception! + if exc: + if 'NameError' in exc: + return [{'id':'name_error', 'args': {'message': exc}}] + elif 'TypeError' in exc: + return [{'id':'type_error', 'args': {'message': exc}}] + else: + return [{'id':'error', 'args': {'message': exc}}] + + # First: if student does not import time, tell him about that module + if not has_token_sequence(code, ['time']): + return [{'id': 'time'}] + + # show plan if student is lost + # a) empty progam or + # b) there is not input (we can do it here, since we have no input hint) + if len(code.strip()) < 5 or (not has_token_sequence(code, ['input'])): + return [{'id': 'plan'}] + + # Student will have to compute time difference and they will need + # the substraction (-) operator to do this. Check for the minus operator. + if not has_token_sequence(code, ['-']): + return [{'id' : 'time_diff'}] + + return None -- cgit v1.2.1