diff options
Diffstat (limited to 'python/problems/introduction/fahrenheit_to_celsius/common.py')
-rw-r--r-- | python/problems/introduction/fahrenheit_to_celsius/common.py | 43 |
1 files changed, 43 insertions, 0 deletions
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 |