summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMartin Možina <martin.mozina@fri.uni-lj.si>2015-10-29 16:08:34 +0100
committerMartin Možina <martin.mozina@fri.uni-lj.si>2015-10-29 16:08:34 +0100
commit5db9e65c81bdf81ed4030040ff3666362e860d10 (patch)
tree70e58eb6d55d9689d3e8b49c9bcadbc7f8458b56 /python
parentec7740df5a94d90758d688ac0f753e12de931360 (diff)
Bugfix.
Added some hints.
Diffstat (limited to 'python')
-rw-r--r--python/problems/functions/body_mass_index/common.py17
-rw-r--r--python/problems/functions/body_mass_index_2/common.py17
-rw-r--r--python/problems/functions/greatest/sl.py6
-rw-r--r--python/problems/functions/greatest_absolutist/sl.py6
-rw-r--r--python/problems/functions/greatest_negative/sl.py4
-rw-r--r--python/problems/functions_and_modules/longest_word/sl.py32
6 files changed, 64 insertions, 18 deletions
diff --git a/python/problems/functions/body_mass_index/common.py b/python/problems/functions/body_mass_index/common.py
index 8e774be..1ff56b6 100644
--- a/python/problems/functions/body_mass_index/common.py
+++ b/python/problems/functions/body_mass_index/common.py
@@ -2,7 +2,7 @@
import re
from python.util import has_token_sequence, string_almost_equal, \
- string_contains_number, get_tokens, get_numbers, get_exception_desc
+ string_contains_number, get_tokens, get_numbers, get_exception_desc, almost_equal
from server.hints import Hint
id = 226
@@ -42,8 +42,19 @@ def test(python, code):
n_correct = 0
tin, tout = None, None
for i, (ans, to) in enumerate(zip(answers, test_out)):
- n_correct += ans[0] == to
- if ans[0] != to:
+ corr = 0
+ if isinstance(ans[0], list) and len(ans[0]) == len(to):
+ corr = 1
+ for v1, v2 in zip(ans[0], to):
+ if not isinstance(v1, tuple) or len(v1) != len(v2):
+ corr = 0
+ break
+ if v1[0] != v2[0] or not almost_equal(v1[1], v2[1], 2):
+ corr = 0
+ break
+
+ n_correct += corr
+ if not corr:
tin = test_in[i][0]
tout = to
diff --git a/python/problems/functions/body_mass_index_2/common.py b/python/problems/functions/body_mass_index_2/common.py
index c6cf2b3..176a59d 100644
--- a/python/problems/functions/body_mass_index_2/common.py
+++ b/python/problems/functions/body_mass_index_2/common.py
@@ -2,7 +2,7 @@
import re
from python.util import has_token_sequence, string_almost_equal, \
- string_contains_number, get_tokens, get_numbers, get_exception_desc
+ string_contains_number, get_tokens, get_numbers, get_exception_desc, almost_equal
from server.hints import Hint
id = 227
@@ -42,8 +42,19 @@ def test(python, code):
n_correct = 0
tin, tout = None, None
for i, (ans, to) in enumerate(zip(answers, test_out)):
- n_correct += ans[0] == to
- if ans[0] != to:
+ corr = 0
+ if isinstance(ans[0], list) and len(ans[0]) == len(to):
+ corr = 1
+ for v1, v2 in zip(ans[0], to):
+ if not isinstance(v1, tuple) or len(v1) != len(v2):
+ corr = 0
+ break
+ if v1[0] != v2[0] or not almost_equal(v1[1], v2[1], 2):
+ corr = 0
+ break
+
+ n_correct += corr
+ if not corr:
tin = test_in[i][0]
tout = to
diff --git a/python/problems/functions/greatest/sl.py b/python/problems/functions/greatest/sl.py
index a32aada..467de07 100644
--- a/python/problems/functions/greatest/sl.py
+++ b/python/problems/functions/greatest/sl.py
@@ -27,7 +27,7 @@ def max_val(xs):
</pre>''']
main_plan = ['''\
-<p><b>Ideja</b>: po vrsti pogledamo vse elemente in sproti hranimo največjega.</p>''',
+<p>Ideja: po vrsti pogledamo vse elemente in sproti hranimo največjega.</p>''',
'''\
<ol>
<li>Začnemo s prvim elementom in si ga zapomnimo kot največjega.</li>
@@ -51,7 +51,7 @@ return_clause = ['''\
<p>Namesto, da izpišemo rezultat, ga vračamo s stavkom <code>return</code>.</p>''']
plan = [['''\
-<p>Najprej poskusi napisati <b>program</b> (brez funkcije), ki v <code>xs</code> poišče največji element</p>''',
+<p>Najprej poskusi napisati program (brez funkcije), ki v <code>xs</code> poišče največji element</p>''',
'''\
<pre>
xs = [5, 1, -6, -7, 2]
@@ -106,7 +106,7 @@ hint = {
'if_clause': if_clause,
'final_hint': '''\
-<p><b>Odlično, naloga rešena! Še zanimivost:</b> Python ima funkcijo <code>max</code> že vgrajeno:</p>
+<p>Odlično, naloga rešena! Še zanimivost: Python ima funkcijo <code>max</code> že vgrajeno:</p>
<pre>
def max_val(xs):
return max(xs)
diff --git a/python/problems/functions/greatest_absolutist/sl.py b/python/problems/functions/greatest_absolutist/sl.py
index 79cfb06..dd0bd99 100644
--- a/python/problems/functions/greatest_absolutist/sl.py
+++ b/python/problems/functions/greatest_absolutist/sl.py
@@ -17,7 +17,7 @@ absolutni vrednosti v seznamu <code>xs</code>.</p>
'''
function = ['''\
-<p>Napiši <b>definicijo funkcije</b> <code>max_abs(xs)</code>.</p>''',
+<p>Napiši definicijo funkcije <code>max_abs(xs)</code>.</p>''',
'''\
<p>Definicijo funkcije začnemo z <code>def</code>, temu sledi ime, potem oklepaji,
v katerih naštejemo argumente funkcije, nato zaklepaj in na koncu dvopičje</p>''',
@@ -31,7 +31,7 @@ print (max_abs(s))
</pre>''']
main_plan = ['''\
-<p><b>Plan</b>: po vrsti pogledamo vse elemente in sproti hranimo največjega
+<p>Plan: po vrsti pogledamo vse elemente in sproti hranimo največjega
(glede na absolutno vrednost).</p>''',
'''\
<pre>
@@ -96,7 +96,7 @@ hint = {
V tem primeru se lahko zgodi, da se zanka ne izteče do konca.</p>''',
'final_hint': '''\
-<p><b>Odlično, naloga rešena! Še zanimivost:</b>
+<p>Odlično, naloga rešena! Še zanimivost:
Tudi to nalogo lahko rešimo s funkcijo <code>max</code>:</p>
<pre>
def max_abs(xs):
diff --git a/python/problems/functions/greatest_negative/sl.py b/python/problems/functions/greatest_negative/sl.py
index 31f1fd6..38a9f08 100644
--- a/python/problems/functions/greatest_negative/sl.py
+++ b/python/problems/functions/greatest_negative/sl.py
@@ -17,7 +17,7 @@ v seznamu <code>xs</code>. Če seznam nima negativnih števil, naj funkcija vrne
'''
function = ['''\
-<p>Napiši <b>definicijo funkcije</b> <code>max_neg(xs)</code>.</p>''',
+<p>Napiši definicijo funkcije <code>max_neg(xs)</code>.</p>''',
'''\
<p>Definicijo funkcije začnemo z <code>def</code>, temu sledi ime, potem oklepaji,
v katerih naštejemo argumente funkcije, nato zaklepaj in na koncu dvopičje</p>''',
@@ -31,7 +31,7 @@ print (max_neg(s))
</pre>''']
main_plan = ['''\
-<p><b>Plan</b>: po vrsti pogledamo vse elemente in sproti hranimo največje negativno
+<p>Plan: po vrsti pogledamo vse elemente in sproti hranimo največje negativno
število.</p>''',
'''\
<p>Na začetku ne moremo največjemu nastaviti vrednosti prvega elementa v seznamu,
diff --git a/python/problems/functions_and_modules/longest_word/sl.py b/python/problems/functions_and_modules/longest_word/sl.py
index eb85509..0d4b057 100644
--- a/python/problems/functions_and_modules/longest_word/sl.py
+++ b/python/problems/functions_and_modules/longest_word/sl.py
@@ -16,11 +16,35 @@ Napiši funkcijo <code>longest(s)</code>, ki vrne najdaljšo besedo v nizu <code
'podgan'
</p>'''
-plan = ['''\
-<p></p>
-''',
+split = ['''\
+<p>
+Uporabi metodo <code>split</code>, ki razdeli niz na podnize.</p>''',
+ '''\
+<pre>
+>>> st = 'an ban pet podgan'
+>>> st.split()
+['an', 'ban', 'pet, 'podgan']
+</pre>
+''']
+
+len_func = [
'''\
-<p></p>''']
+<p>Funkcija <code>len</code> vrne dolžino niza (pa tudi seznama, terke, itd.)</p>''']
+
+
+
+
+plan = [split,
+'''\
+<pre>
+def longest(s):
+ z zanko čez vse besede
+ če je beseda daljša od trenutno najdaljše besede
+ ustrezno spremeni najdaljšo besedo
+ vrni rezultat
+</pre>
+''',
+ len_func]
hint = {
'final_hint': ['''\