summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin <martin@leo.fri1.uni-lj.si>2015-10-08 11:17:16 +0200
committerMartin <martin@leo.fri1.uni-lj.si>2015-10-08 11:17:16 +0200
commit1f9f6de923e4b490c42a44d660b3e32dbe11426e (patch)
treef103aa69d256f5985bdf4815b64e33af0664d88a
parentbab0b0a2fe8b3aad853740750d4873fb929f5f41 (diff)
Added final hint to contains_42.
-rw-r--r--python/problems/introduction/fahrenheit_to_celsius/common.py4
-rw-r--r--python/problems/introduction/fahrenheit_to_celsius/sl.py2
-rw-r--r--python/problems/lists_and_for/contains_42/common.py14
-rw-r--r--python/problems/lists_and_for/contains_42/sl.py21
4 files changed, 33 insertions, 8 deletions
diff --git a/python/problems/introduction/fahrenheit_to_celsius/common.py b/python/problems/introduction/fahrenheit_to_celsius/common.py
index 6549c32..918c643 100644
--- a/python/problems/introduction/fahrenheit_to_celsius/common.py
+++ b/python/problems/introduction/fahrenheit_to_celsius/common.py
@@ -3,6 +3,7 @@
from python.util import has_token_sequence, string_almost_equal, \
string_contains_number, get_tokens, get_numbers, get_exception_desc
from server.hints import Hint
+import re
id = 180
group = 'introduction'
@@ -87,6 +88,9 @@ def hint(python, code):
if not has_token_sequence(tokens, ['input']):
return [{'id': 'no_input_call'}]
+ if not re.findall(r'=[^\n]*?input', code):
+ return [{'id': 'no_input_call'}]
+
# if tokens * or / or = are not in code, we have to teach them how to
# evaluate expressions.
if (not has_token_sequence(tokens, ['/']) or
diff --git a/python/problems/introduction/fahrenheit_to_celsius/sl.py b/python/problems/introduction/fahrenheit_to_celsius/sl.py
index b61c436..ae3db5f 100644
--- a/python/problems/introduction/fahrenheit_to_celsius/sl.py
+++ b/python/problems/introduction/fahrenheit_to_celsius/sl.py
@@ -12,7 +12,7 @@ stopinjah, program pa jo izpiše v Celzijevih. Med temperaturama pretvarjamo po
formuli C = 5/9 (F – 32).</p>'''
no_input_call = ['''\
-<p>Uporabnika nekaj vprašamo s funkcijo <code>input</code>.</p>''',
+<p>Uporabi funkcijo <code>input</code> in shrani rezultat.</p>''',
'''\
<p>Funkcija <code>input</code> sprejme niz (<em>angl.</em> string), ki se
prikaže uporabniku kot vprašanje in vrača, kar je uporabnik napisal. </p>''',
diff --git a/python/problems/lists_and_for/contains_42/common.py b/python/problems/lists_and_for/contains_42/common.py
index f91465f..d4c4af8 100644
--- a/python/problems/lists_and_for/contains_42/common.py
+++ b/python/problems/lists_and_for/contains_42/common.py
@@ -25,10 +25,15 @@ hint_type = {
'for_loop': Hint('for_loop'),
'if_clause': Hint('if_clause'),
'printing': Hint('printing'),
- 'print_out_for': Hint('print_out_for')
+ 'print_out_for': Hint('print_out_for'),
+ 'seen_42': Hint('seen_42'),
+ 'final_hint': Hint('final_hint'),
+ 'final_hint_nobreak': Hint('final_hint_nobreak')
}
def test(python, code):
+ tokens = get_tokens(code)
+
test_xs = [[42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2],
[42, 5, 4, -7, 2, 12, -3, -4, 11, 2],
[5, 4, -7, 2, 12, -3, -4, 11, 2],
@@ -71,6 +76,11 @@ def test(python, code):
hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_xs)}}]
if tin:
hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ else:
+ if has_token_sequence(tokens, ['break']):
+ hints.append({'id' : 'final_hint'})
+ else:
+ hints.append({'id' : 'final_hint_nobreak'})
return passed, hints
def hint(python, code):
@@ -101,5 +111,7 @@ def hint(python, code):
if not has_token_sequence(tokens, ['\n', 'print']):
return [{'id' : 'print_out_for'}]
+ if not has_token_sequence(tokens, ['=', 'True']):
+ return [{'id' : 'seen_42'}]
return None
diff --git a/python/problems/lists_and_for/contains_42/sl.py b/python/problems/lists_and_for/contains_42/sl.py
index fe6b57e..1a40549 100644
--- a/python/problems/lists_and_for/contains_42/sl.py
+++ b/python/problems/lists_and_for/contains_42/sl.py
@@ -21,10 +21,10 @@ Seveda mora program delati za poljubne sezname in ne samo za seznam iz primera.<
for_loop = ['''\
<p>Pregledati bo treba vse elemente v seznamu <code>xs</code>''',
'''\
-<p>Najlažje bo s <b>for</b> zanko.
+<p>Najlažje bo s <code>for</code> zanko.
''',
'''\
-<p>Poskusii naslednji dve vrstici:</p>
+<p>Poskusi naslednji dve vrstici:</p>
<pre>
for x in xs:
print (x)
@@ -36,9 +36,9 @@ Kaj naj Python naredi s to spremenljivko, je zapisano v zamaknjenih vrsticah.
Tokrat vrednost le izpišemo.</p>''']
if_clause = ['''\
-<p><code>Preveri, ali imamo število 42?</code></p>''',
+<p>Preveri, ali imamo število 42?</p>''',
'''\
-<p>Uporabi pogojni stavek <b>if</b>!</p>''',
+<p>Uporabi pogojni stavek <code>if</code>!</p>''',
'''\
<pre>
if x == 42:
@@ -57,7 +57,7 @@ videl42 = False
<p>in jo tekom zanke ustrezno spremenimo.''']
plan = ['''\
-<p><b>Plan.</b> Kako bi se tega lotil ročno? Nekako takole: </p>
+<p>Kako bi se tega lotil ročno? Nekako takole: </p>
<pre>
Za vsak element v seznamu
Poglej, ali je 42?
@@ -82,6 +82,15 @@ hint = {
<p>Izpiši rezultat.</p>'''],
'print_out_for': ['''\
-<p>Pazi, da izpišeš rezultat izven zanke!</p>''']
+<p>Pazi, da izpišeš rezultat izven zanke!</p>'''],
+ 'seen_42': seen_42,
+
+ 'final_hint': ['''\
+<p>Program deluje pravilno!</p>'''],
+
+ 'final_hint_nobreak': ['''\
+<p>Program deluje pravilno! <br>
+Namig za bolj učinkovit program: ni vedno potrebno, da se program pregleda vse elemente. Če najdemo vrednost 42, nam ni
+potrebno več naprej iskati - zanko lahko prekinemo z ukazom <code>break</code> </p>'''],
}