summaryrefslogtreecommitdiff
path: root/python/problems/introduction/fahrenheit_to_celsius/common.py
blob: 1555cf79d54696a3d6e5a68d3bc05f1cc75d154a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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.util import has_token_sequence

def test(session, 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 = session.get_python().run(code=code, inputs=test_in, timeout=1.0)
    outputs = [ans[1] for ans in answers]

    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(session, code):
    if not code:
        return [{'id': 'plan'}]
    if not has_token_sequence(code, ['input']):
        return [{'id': 'no_input_call'}]
    return None