From e35f80372f283b81333a8260b07905848ea5f37d Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 31 Aug 2015 15:44:29 +0200 Subject: Add the first Python problem definition --- .../introduction/fahrenheit_to_celsius/common.py | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 python/problems/introduction/fahrenheit_to_celsius/common.py (limited to 'python/problems/introduction/fahrenheit_to_celsius/common.py') diff --git a/python/problems/introduction/fahrenheit_to_celsius/common.py b/python/problems/introduction/fahrenheit_to_celsius/common.py new file mode 100644 index 0000000..a13687d --- /dev/null +++ b/python/problems/introduction/fahrenheit_to_celsius/common.py @@ -0,0 +1,43 @@ +# coding=utf-8 + +id = 180 +group = 'introduction' +number = 1 +visible = True + +solution = '''\ +f = float(input("Temperatura [F]: ")) + c = 5/9 * (f – 32) +print("Temperatura je", c, "C") +''' + +from python.engine import run +from python.util import has_token_sequence + +def test(code): + # List of inputs: (expression to eval, stdin). + test_in = [ + (None, '0\n'), + (None, '100\n'), + ] + test_out = [ + '-17.7', + '37.7', + ] + + # List of outputs: (expression result, stdout, stderr, exception). + answers = run(code=code, inputs=test_in, timeout=1.0) + outputs = [ans[1] for ans in answers['results']] + + n_correct = 0 + for output, correct in zip(outputs, test_out): + if correct in output: + n_correct += 1 + return n_correct, len(test_in) + +def hint(code): + if not code: + return [{'id': 'plan'}] + if not has_token_sequence(code, ['input']): + return [{'id': 'no_input_call'}] + return None -- cgit v1.2.1