summaryrefslogtreecommitdiff
path: root/python/problems/introduction/fahrenheit_to_celsius/common.py
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-08-31 15:44:29 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-08-31 15:44:29 +0200
commite35f80372f283b81333a8260b07905848ea5f37d (patch)
tree58bc0269adf8e6b52f4d13a0c5834b708bdc38cf /python/problems/introduction/fahrenheit_to_celsius/common.py
parentda9ac95a54f3be7128aace4c09ad0d7b085cd788 (diff)
Add the first Python problem definition
Diffstat (limited to 'python/problems/introduction/fahrenheit_to_celsius/common.py')
-rw-r--r--python/problems/introduction/fahrenheit_to_celsius/common.py43
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