summaryrefslogtreecommitdiff
path: root/python/problems/introduction
diff options
context:
space:
mode:
Diffstat (limited to 'python/problems/introduction')
-rw-r--r--python/problems/introduction/fahrenheit_to_celsius/common.py43
-rw-r--r--python/problems/introduction/fahrenheit_to_celsius/en.py18
-rw-r--r--python/problems/introduction/fahrenheit_to_celsius/sl.py32
3 files changed, 93 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
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 = '''\
+<p>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).</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
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 = '''\
+<p>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).</p>'''
+
+hint = {
+ 'plan' = '''\
+<p>Za začetek lahko razdelimo program na 3 dele:</p>
+<ol>
+ <li>Vprašanje za temperaturo v Fahrenheitih (F = ?).</li>
+ <li>Izračun temperature v Celzijih: C = 5/9 (F – 32)</li>
+ <li>Izpis temperature v Celzijih (izpiši C).</li>
+</ol>''',
+
+ 'no_input_call' = '''\
+<p>Uporabnika lahko nekaj vprašamo s funkcijo <code>input</code>. Funkcija
+<code>input</code> sprejme kot argument niz (<em>angl.</em> 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:</p>
+<pre>
+ime = input("Kako ti je ime?")
+</pre>
+<p>pokliče funkcijo <code>input</code>, ki povpraša uporabnika po imenu in si
+shrani uporabnikov odgovor v spremenljivko <code>ime</code>.</p>''',
+}