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 ++++++++++++++++++++++ .../introduction/fahrenheit_to_celsius/en.py | 18 +++++++++ .../introduction/fahrenheit_to_celsius/sl.py | 32 ++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 python/problems/introduction/fahrenheit_to_celsius/common.py create mode 100644 python/problems/introduction/fahrenheit_to_celsius/en.py create mode 100644 python/problems/introduction/fahrenheit_to_celsius/sl.py (limited to 'python/problems') 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 diff --git a/python/problems/introduction/fahrenheit_to_celsius/en.py b/python/problems/introduction/fahrenheit_to_celsius/en.py new file mode 100644 index 0000000..a2af212 --- /dev/null +++ b/python/problems/introduction/fahrenheit_to_celsius/en.py @@ -0,0 +1,18 @@ +# coding=utf-8 + +id = 180 +name = 'Converting Fahrenheit to Celsius' +slug = 'Converting Fahrenheit to Celsius' + +description = '''\ +

Write a program that reads a temperature in degrees Fahrenheit from the +user, and prints the same temperature converted to degrees Celsius. The +conversion formula is C = 5/9 (F – 32).

''' + +hint = { + 'plan': '''\ +

(translation missing)

''', + + 'no_input_call': '''\ +

(translation missing)

''', +} diff --git a/python/problems/introduction/fahrenheit_to_celsius/sl.py b/python/problems/introduction/fahrenheit_to_celsius/sl.py new file mode 100644 index 0000000..f13037c --- /dev/null +++ b/python/problems/introduction/fahrenheit_to_celsius/sl.py @@ -0,0 +1,32 @@ +# coding=utf-8 + +id = 180 +name = 'Pretvarjanje iz Fahrenheitov v Celzije' +slug = 'Pretvarjanje iz Fahrenheitov v Celzije' + +description = '''\ +

Napiši program, ki mu uporabnik vpiše temperaturo v Fahrenheitovih +stopinjah, program pa jo izpiše v Celzijevih. Med temperaturama pretvarjamo po +formuli C = 5/9 (F – 32).

''' + +hint = { + 'plan' = '''\ +

Za začetek lahko razdelimo program na 3 dele:

+
    +
  1. Vprašanje za temperaturo v Fahrenheitih (F = ?).
  2. +
  3. Izračun temperature v Celzijih: C = 5/9 (F – 32)
  4. +
  5. Izpis temperature v Celzijih (izpiši C).
  6. +
''', + + 'no_input_call' = '''\ +

Uporabnika lahko nekaj vprašamo s funkcijo input. Funkcija +input sprejme kot argument niz (angl. string), ki se +prikaže uporabniku kot vprašanje in vrne niz, ki ga je uporabnik napisal. Nize +zapisujemo v narekovaje (lahko so enojni ali dvojni). Npr., naslednja +vrstica:

+
+ime = input("Kako ti je ime?")
+
+

pokliče funkcijo input, ki povpraša uporabnika po imenu in si +shrani uporabnikov odgovor v spremenljivko ime.

''', +} -- cgit v1.2.1