summaryrefslogtreecommitdiff
path: root/python/problems/lists_and_for
diff options
context:
space:
mode:
Diffstat (limited to 'python/problems/lists_and_for')
-rw-r--r--python/problems/lists_and_for/calculator_polish/common.py70
-rw-r--r--python/problems/lists_and_for/calculator_polish/en.py16
-rw-r--r--python/problems/lists_and_for/calculator_polish/sl.py61
-rw-r--r--python/problems/lists_and_for/contains_multiples/common.py49
-rw-r--r--python/problems/lists_and_for/contains_multiples/en.py16
-rw-r--r--python/problems/lists_and_for/contains_multiples/sl.py29
-rw-r--r--python/problems/lists_and_for/divisors/common.py4
-rw-r--r--python/problems/lists_and_for/divisors/sl.py2
-rw-r--r--python/problems/lists_and_for/divisors_sum/common.py111
-rw-r--r--python/problems/lists_and_for/divisors_sum/en.py16
-rw-r--r--python/problems/lists_and_for/divisors_sum/sl.py101
-rw-r--r--python/problems/lists_and_for/every_third/common.py50
-rw-r--r--python/problems/lists_and_for/every_third/en.py16
-rw-r--r--python/problems/lists_and_for/every_third/sl.py35
-rw-r--r--python/problems/lists_and_for/perfect_numbers/common.py114
-rw-r--r--python/problems/lists_and_for/perfect_numbers/en.py16
-rw-r--r--python/problems/lists_and_for/perfect_numbers/sl.py96
-rw-r--r--python/problems/lists_and_for/places/common.py49
-rw-r--r--python/problems/lists_and_for/places/en.py16
-rw-r--r--python/problems/lists_and_for/places/sl.py32
-rw-r--r--python/problems/lists_and_for/prefix/common.py48
-rw-r--r--python/problems/lists_and_for/prefix/en.py16
-rw-r--r--python/problems/lists_and_for/prefix/sl.py31
-rw-r--r--python/problems/lists_and_for/split_word/common.py48
-rw-r--r--python/problems/lists_and_for/split_word/en.py16
-rw-r--r--python/problems/lists_and_for/split_word/sl.py31
-rw-r--r--python/problems/lists_and_for/substrings/common.py51
-rw-r--r--python/problems/lists_and_for/substrings/en.py16
-rw-r--r--python/problems/lists_and_for/substrings/sl.py33
29 files changed, 1186 insertions, 3 deletions
diff --git a/python/problems/lists_and_for/calculator_polish/common.py b/python/problems/lists_and_for/calculator_polish/common.py
new file mode 100644
index 0000000..d08f19c
--- /dev/null
+++ b/python/problems/lists_and_for/calculator_polish/common.py
@@ -0,0 +1,70 @@
+# coding=utf-8
+
+import re
+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
+
+id = 224
+group = 'lists_and_for'
+number = 10
+visible = True
+
+solution = '''\
+operacije = ["*", "+", "-", "/", "%"]
+
+while True:
+ izraz = input("Izraz: ").split()
+ if not izraz:
+ break
+
+ sklad = []
+ for e in izraz:
+ sklad.append(e)
+ if sklad[-1] in operacije:
+ operacija = sklad.pop()
+ o2 = int(sklad.pop())
+ o1 = int(sklad.pop())
+ if operacija == "+":
+ rezultat = o1 + o2
+ elif operacija == "-":
+ rezultat = o1 - o2
+ elif operacija == "*":
+ rezultat = o1 * o2
+ elif operacija == "/":
+ rezultat = o1 // o2
+ elif operacija == "%":
+ rezultat = o1 % o2
+ sklad.append(rezultat)
+
+ print("Rezultat:", sklad[0])
+ print()
+'''
+
+hint_type = {
+ 'final_hint': Hint('final_hint')
+}
+
+def test(python, code):
+ test_in = [1]
+ n_correct = 0
+
+ passed = n_correct == len(test_in)
+ tin = None
+ tout = None
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, None)], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc: return exc
+
+ return None
diff --git a/python/problems/lists_and_for/calculator_polish/en.py b/python/problems/lists_and_for/calculator_polish/en.py
new file mode 100644
index 0000000..f0618e8
--- /dev/null
+++ b/python/problems/lists_and_for/calculator_polish/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 224
+name = 'Reverse polish potation calculator'
+slug = 'Reverse polish potation calculator'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/calculator_polish/sl.py b/python/problems/lists_and_for/calculator_polish/sl.py
new file mode 100644
index 0000000..b7ff8a1
--- /dev/null
+++ b/python/problems/lists_and_for/calculator_polish/sl.py
@@ -0,0 +1,61 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 224
+name = 'Kalkulator v inverzni poljski notaciji'
+slug = 'Kalkulator v inverzni poljski notaciji'
+
+
+description = '''\
+<p>
+V <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation">inverzni poljski ali postfiksni notaciji</a> ne potrebujemo oklepajev:
+računska operacija sledi številoma in se vedno izvede takoj ter zamenja predhodni števili in operacijo z rezultatom operacije.
+
+Poglejmo si računanje <code>(3 + 5) * 2 - 10 * (2 - 1)</code> ali postfiksno <code>3 5 + 2 * 10 2 1 - * -</code>:
+
+<ul>
+<li> Beremo vhod do prve operacije. </li>
+<li> <code>3 5 + </code>; izvede se seštevanje, tri elemente zamenja rezultat 8, beremo dalje. </li>
+<li> <code>8 2 * </code>; rezultat je 16, beremo dalje.</li>
+<li> <code>16 10 2 1 -</code>; rezultat 1, beremo dalje.</li>
+<li> <code>16 10 1 *</code>; rezultat 10, beremo dalje.</li>
+<li> <code>16 10 -</code>; rezultat 6, beremo dalje.</li>
+<li> <code>6</code>; vhoda je konec zato se se računanje ustavi.</li>
+</ul>
+Napišite kalkulator s celoštevilskimi operacijami seštevanja, odštevanja, množenja, deljenja in izračunom ostanka,
+ki prejme vhod v inverzni poljski notaciji. Ko uporabnik ne poda ničesar (pritisne le enter), naj se program zaključi.
+Števila ter operande ločujte s presledkom.
+<pre>
+Izraz: 3 5 +
+Rezultat: 8
+
+Izraz: 16 5 %
+Rezultat: 1
+
+Izraz: 16 5 /
+Rezultat: 3
+
+Izraz: 3 3 3 + +
+Rezultat: 9
+
+Izraz: 3 5 + 2 * 10 2 1 - * -
+Rezultat: 6
+
+Izraz:
+</pre>
+</p>'''
+
+plan = ['''\
+<p></p>
+''',
+ '''\
+<p></p>''']
+
+hint = {
+ 'final_hint': ['''\
+<p>Program je pravilen! <br>
+</p>
+'''],
+}
diff --git a/python/problems/lists_and_for/contains_multiples/common.py b/python/problems/lists_and_for/contains_multiples/common.py
new file mode 100644
index 0000000..8bdcc36
--- /dev/null
+++ b/python/problems/lists_and_for/contains_multiples/common.py
@@ -0,0 +1,49 @@
+# coding=utf-8
+
+import re
+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
+
+id = 219
+group = 'lists_and_for'
+number = 5
+visible = True
+
+solution = '''\
+xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2]
+
+vsebuje = False
+for x in xs:
+ if x % 42 == 0:
+ vsebuje = True
+print(vsebuje)
+'''
+
+hint_type = {
+ 'final_hint': Hint('final_hint')
+}
+
+def test(python, code):
+ test_in = [1]
+ n_correct = 0
+
+ passed = n_correct == len(test_in)
+ tin = None
+ tout = None
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, None)], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc: return exc
+
+ return None
diff --git a/python/problems/lists_and_for/contains_multiples/en.py b/python/problems/lists_and_for/contains_multiples/en.py
new file mode 100644
index 0000000..47bf004
--- /dev/null
+++ b/python/problems/lists_and_for/contains_multiples/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 219
+name = 'Contains multiples'
+slug = 'Contains multiples'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/contains_multiples/sl.py b/python/problems/lists_and_for/contains_multiples/sl.py
new file mode 100644
index 0000000..ae4c845
--- /dev/null
+++ b/python/problems/lists_and_for/contains_multiples/sl.py
@@ -0,0 +1,29 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 219
+name = 'Vsebuje večkratnik'
+slug = 'Vsebuje večkratnik'
+
+
+description = '''\
+<p>
+Napiši program, ki izpiše <code>True</code>, če se v seznamu števil pojavi večkratnik števila
+<code>42</code>, sicer izpiše <code>False</code>.
+Seznam <code>xs</code> definiraj na vrhu programa.
+</p>'''
+
+plan = ['''\
+<p></p>
+''',
+ '''\
+<p></p>''']
+
+hint = {
+ 'final_hint': ['''\
+<p>Program je pravilen! <br>
+</p>
+'''],
+}
diff --git a/python/problems/lists_and_for/divisors/common.py b/python/problems/lists_and_for/divisors/common.py
index 4f440e4..f9334be 100644
--- a/python/problems/lists_and_for/divisors/common.py
+++ b/python/problems/lists_and_for/divisors/common.py
@@ -7,8 +7,8 @@ from server.hints import Hint
id = 204
group = 'lists_and_for'
-number = 4
-visible = True
+number = 20
+visible = False
solution = '''\
n = int(input('Vnesi število: '))
diff --git a/python/problems/lists_and_for/divisors/sl.py b/python/problems/lists_and_for/divisors/sl.py
index cddeae8..3edf2bb 100644
--- a/python/problems/lists_and_for/divisors/sl.py
+++ b/python/problems/lists_and_for/divisors/sl.py
@@ -78,7 +78,7 @@ hint = {
<p>Naloga rešena!</p>
<p>Dejansko ne potrebujemo pregledati vseh števil med <code>1</code> in <code>n-1</code>,
- dovolj bo če gremo do kvadratnega korena od števila <code>n</code>:</p>
+ dovolj bo če gremo do kvadratnega korena števila <code>n</code>:</p>
<pre>
from math import *
diff --git a/python/problems/lists_and_for/divisors_sum/common.py b/python/problems/lists_and_for/divisors_sum/common.py
new file mode 100644
index 0000000..651f657
--- /dev/null
+++ b/python/problems/lists_and_for/divisors_sum/common.py
@@ -0,0 +1,111 @@
+# coding=utf-8
+
+import re
+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
+
+id = 216
+group = 'lists_and_for'
+number = 21
+visible = False
+
+solution = '''\
+n = int(input('Vnesi število: '))
+vsota = 0
+for i in range(1, n):
+ if n % i == 0:
+ vsota += i
+print(vsota)
+'''
+
+hint_type = {
+ 'input_clause': Hint('input_clause'),
+ 'range_function': Hint('range_function'),
+ 'printing': Hint('printing'),
+ 'divisor': Hint('divisor'),
+ 'final_hint': Hint('final_hint'),
+ 'zero_division': Hint('zero_division'),
+ 'last_number': Hint('last_number'),
+ 'summing': Hint('summing'),
+}
+
+def test(python, code):
+ test_in = [
+ (None, '8\n'),
+ (None, '6\n'),
+ (None, '5\n'),
+ (None, '2\n'),
+ (None, '15\n'),
+ (None, '20\n'),
+ ]
+ test_out = [
+ 7,
+ 6,
+ 1,
+ 1,
+ 9,
+ 22]
+
+ # List of outputs: (expression result, stdout, stderr, exception).
+ answers = python(code=code, inputs=test_in, timeout=1.0)
+ outputs = [ans[1] for ans in answers]
+
+ n_correct, tin = 0, None
+ for i, (output, result) in enumerate(zip(outputs, test_out)):
+ if result in get_numbers(output):
+ n_correct += 1
+ else:
+ tin = test_in[i][1]
+ tout = result
+
+ passed = n_correct == len(test_in)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, '8\n')], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc:
+ if 'ZeroDivisionError' in answer[0][3]:
+ return [{'id' : 'zero_division', 'args': {'message': answer[0][3]}}]
+ else:
+ return exc
+
+ # if has no input, tell him how to ask questions
+ if not has_token_sequence(tokens, ['input']):
+ return [{'id' : 'input_clause'}]
+
+ # if it has no range, explain how we can create a list (generator) from a number
+ if not has_token_sequence(tokens, ['range']):
+ return [{'id' : 'range_function'}]
+
+ # if it has no print function, tell him to use print
+ if not has_token_sequence(tokens, ['print']):
+ return [{'id' : 'printing'}]
+
+ # if it has no divisoin-by-modulo operator, explain that operator
+ if not has_token_sequence(tokens, ['%']):
+ return [{'id' : 'divisor'}]
+
+ # if the program prints 15 instead of 7,
+ # it means that is adds also itself
+ nums = get_numbers(answer[0][1])
+ if 15 in nums and 7 not in nums:
+ return [{'id' : 'last_number'}]
+
+ # if program prints only the last number or
+ # only the first number, explain how to sum
+ # elements in iterations
+ if 7 not in nums and \
+ (1 in nums or 4 in nums or 8 in nums):
+ return [{'id' : 'summing'}]
+
+
+ return None
diff --git a/python/problems/lists_and_for/divisors_sum/en.py b/python/problems/lists_and_for/divisors_sum/en.py
new file mode 100644
index 0000000..4ca12b9
--- /dev/null
+++ b/python/problems/lists_and_for/divisors_sum/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 216
+name = 'Divisors sum'
+slug = 'Divisors sum'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/divisors_sum/sl.py b/python/problems/lists_and_for/divisors_sum/sl.py
new file mode 100644
index 0000000..4f5c10a
--- /dev/null
+++ b/python/problems/lists_and_for/divisors_sum/sl.py
@@ -0,0 +1,101 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 216
+name = 'Vsota deliteljev'
+slug = 'Vsota deliteljev'
+
+
+description = '''\
+<p> Napiši program, ki izpiše vsoto vseh deliteljev števila, ki ga vnese uporabnik.
+Med delitelji izpustite vnešeno število. Primer: </p>
+<pre>
+>>> Vpiši število: 6
+Vsota deliteljev: 6
+</pre>'''
+
+input_clause = ['''\
+Uporabi funkcijo <code>input</code>.
+''']
+
+range_function = ['''\
+Uporabi funkcijo <code>range(a,b)</code>
+''',
+ '''\
+<p>Funkcija <code>range(a, b)</code> pripravi seznam števil od a do števila b-1. Poskusi!</p>''',
+ '''\
+<p>Z zanko <code>for</code> se sprehodi čez elemente seznama oz. v našem primeru
+čez vsa števila od <code>a</code> do <code>b-1</code>.</p>
+''']
+
+divisor = ['''\
+<p>Operator % vrne ostanek pri deljenju.</p>''',
+ '''\
+<pre>
+>>> 5%3
+2
+>>> 17%8
+1
+</pre>''',
+ '''\
+<p>Če je ostanek pri deljenju števila <code>a</code> s številom <code>b</code> enak 0, potem <code>b</code>
+deli število <code>a</code>. </p>''',
+ '''\
+<pre>
+if a%b == 0:
+ # b je delitelj števila a
+</pre>
+''']
+
+summing = ['''\
+<p>Če hočemo delitelje prišteti vsoti, moramo imeti vsoto nekje shranjeno.
+Torej potrebujemo spremenljivko.</p>''',
+ '''\
+<p>Nekako tako: </p>
+<pre>
+vsota = 0
+for ....
+ if ...
+ vsota += d # d deli izbrano število
+</pre>''']
+
+plan = ['''\
+<p>Plan bo podoben kot v prejšnji naloge, kjer smo delitelje izpisali.
+Tokrat delitelja ne izpišemo, ampak ga prištejemo vsoti. </p>
+''',
+ summing]
+
+
+hint = {
+ 'input_clause': input_clause,
+
+ 'range_function': range_function,
+
+ 'printing': ['''\
+<p>Izpiši rezultat.</p>'''],
+
+ 'divisor': divisor,
+
+ 'last_number': ['''\
+<p>Tokrat med delitelji ne upoštevamo vnešenega števila!</p>'''],
+
+ 'final_hint': ['''\
+<p>Naloga rešena! <br>
+Nakoč bomo znali to napisati krajše: </p>
+<pre>
+n = int(input("Vpiši število: "))
+print(sum(i for i in range(1, n) if n % i == 0))
+</pre>'''],
+
+ 'summing': summing,
+
+ 'zero_division': [mod.general_msg['error_head'],
+ mod.general_msg['general_exception'],
+ '''\
+<p>Deljenje z nič ni dovoljeno!</p>''',
+ '''\
+<p>Računanje ostanka z operatorjem % je tudi deljenje.''']
+
+}
diff --git a/python/problems/lists_and_for/every_third/common.py b/python/problems/lists_and_for/every_third/common.py
new file mode 100644
index 0000000..9c27446
--- /dev/null
+++ b/python/problems/lists_and_for/every_third/common.py
@@ -0,0 +1,50 @@
+# coding=utf-8
+
+import re
+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
+
+id = 220
+group = 'lists_and_for'
+number = 6
+visible = True
+
+solution = '''\
+xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2]
+
+ys = []
+i = 2
+while i < len(xs):
+ ys.append(xs[i])
+ i += 3
+print(ys)
+'''
+
+hint_type = {
+ 'final_hint': Hint('final_hint')
+}
+
+def test(python, code):
+ test_in = [1]
+ n_correct = 0
+
+ passed = n_correct == len(test_in)
+ tin = None
+ tout = None
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, None)], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc: return exc
+
+ return None
diff --git a/python/problems/lists_and_for/every_third/en.py b/python/problems/lists_and_for/every_third/en.py
new file mode 100644
index 0000000..e7c843e
--- /dev/null
+++ b/python/problems/lists_and_for/every_third/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 220
+name = 'Every third'
+slug = 'Every third'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/every_third/sl.py b/python/problems/lists_and_for/every_third/sl.py
new file mode 100644
index 0000000..3bac8a3
--- /dev/null
+++ b/python/problems/lists_and_for/every_third/sl.py
@@ -0,0 +1,35 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 220
+name = 'Vsak tretji'
+slug = 'Vsak tretji'
+
+
+description = '''\
+<p>
+Napiši program, ki iz podanega seznama sestavi nov seznam, ki vsebuje le vsak tretji element podanega seznama.
+Kot dosedaj, naj se program začne z
+<pre>
+xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2]
+</pre>
+in (v tem primeru) izpiše
+<pre>
+[4, 12, 11]
+</pre>
+</p>'''
+
+plan = ['''\
+<p></p>
+''',
+ '''\
+<p></p>''']
+
+hint = {
+ 'final_hint': ['''\
+<p>Program je pravilen! <br>
+</p>
+'''],
+}
diff --git a/python/problems/lists_and_for/perfect_numbers/common.py b/python/problems/lists_and_for/perfect_numbers/common.py
new file mode 100644
index 0000000..c1c7645
--- /dev/null
+++ b/python/problems/lists_and_for/perfect_numbers/common.py
@@ -0,0 +1,114 @@
+# coding=utf-8
+
+import re
+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
+
+id = 217
+group = 'lists_and_for'
+number = 22
+visible = False
+
+solution = '''\
+n = int(input('Vnesi število: '))
+vsota = 0
+for i in range(1, n):
+ if n % i == 0:
+ vsota += i
+if vsota == n:
+ print('Je popolno')
+else:
+ print('Ni popolno')
+'''
+
+hint_type = {
+ 'input_clause': Hint('input_clause'),
+ 'range_function': Hint('range_function'),
+ 'printing': Hint('printing'),
+ 'divisor': Hint('divisor'),
+ 'final_hint': Hint('final_hint'),
+ 'zero_division': Hint('zero_division'),
+ 'last_number': Hint('last_number'),
+ 'summing': Hint('summing'),
+}
+
+def test(python, code):
+ test_in = [
+ (None, '8\n'),
+ (None, '6\n'),
+ (None, '5\n'),
+ (None, '2\n'),
+ (None, '15\n'),
+ (None, '20\n'),
+ ]
+ test_out = [
+ 7,
+ 6,
+ 1,
+ 1,
+ 9,
+ 22]
+
+ # List of outputs: (expression result, stdout, stderr, exception).
+ answers = python(code=code, inputs=test_in, timeout=1.0)
+ outputs = [ans[1] for ans in answers]
+
+ n_correct, tin = 0, None
+ for i, (output, result) in enumerate(zip(outputs, test_out)):
+ if result in get_numbers(output):
+ n_correct += 1
+ else:
+ tin = test_in[i][1]
+ tout = result
+
+ passed = n_correct == len(test_in)
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, '8\n')], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc:
+ if 'ZeroDivisionError' in answer[0][3]:
+ return [{'id' : 'zero_division', 'args': {'message': answer[0][3]}}]
+ else:
+ return exc
+
+ # if has no input, tell him how to ask questions
+ if not has_token_sequence(tokens, ['input']):
+ return [{'id' : 'input_clause'}]
+
+ # if it has no range, explain how we can create a list (generator) from a number
+ if not has_token_sequence(tokens, ['range']):
+ return [{'id' : 'range_function'}]
+
+ # if it has no print function, tell him to use print
+ if not has_token_sequence(tokens, ['print']):
+ return [{'id' : 'printing'}]
+
+ # if it has no divisoin-by-modulo operator, explain that operator
+ if not has_token_sequence(tokens, ['%']):
+ return [{'id' : 'divisor'}]
+
+ # if the program prints 15 instead of 7,
+ # it means that is adds also itself
+ nums = get_numbers(answer[0][1])
+ if 15 in nums and 7 not in nums:
+ return [{'id' : 'last_number'}]
+
+ # if program prints only the last number or
+ # only the first number, explain how to sum
+ # elements in iterations
+ if 7 not in nums and \
+ (1 in nums or 4 in nums or 8 in nums):
+ return [{'id' : 'summing'}]
+
+
+ return None
diff --git a/python/problems/lists_and_for/perfect_numbers/en.py b/python/problems/lists_and_for/perfect_numbers/en.py
new file mode 100644
index 0000000..19d5262
--- /dev/null
+++ b/python/problems/lists_and_for/perfect_numbers/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 217
+name = 'Perfect number'
+slug = 'Perfect number'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/perfect_numbers/sl.py b/python/problems/lists_and_for/perfect_numbers/sl.py
new file mode 100644
index 0000000..bc02d00
--- /dev/null
+++ b/python/problems/lists_and_for/perfect_numbers/sl.py
@@ -0,0 +1,96 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 217
+name = 'Popolna števila'
+slug = 'Popolna števila'
+
+
+description = '''\
+<p> Napiši program, ki izpiše "je popolno", če je podano število popolno, oz.
+"ni popolno", če ni. Popolna števila so števila, ki so enaka vsoti svojih
+deliteljev (brez samega sebe). Primer popolnega števila je 28,
+saj so njegovi delitelji 1, 2, 4, 7, 14, njihova vsota,
+1+2+4+7+14 pa je spet enaka 28. </p>'''
+
+input_clause = ['''\
+Uporabi funkcijo <code>input</code>.
+''']
+
+range_function = ['''\
+Uporabi funkcijo <code>range(a,b)</code>
+''',
+ '''\
+<p>Funkcija <code>range(a, b)</code> pripravi seznam števil od a do števila b-1. Poskusi!</p>''',
+ '''\
+<p>Z zanko <code>for</code> se sprehodi čez elemente seznama oz. v našem primeru
+čez vsa števila od <code>a</code> do <code>b-1</code>.</p>
+''']
+
+divisor = ['''\
+<p>Operator % vrne ostanek pri deljenju.</p>''',
+ '''\
+<pre>
+>>> 5%3
+2
+>>> 17%8
+1
+</pre>''',
+ '''\
+<p>Če je ostanek pri deljenju števila <code>a</code> s številom <code>b</code> enak 0, potem <code>b</code>
+deli število <code>a</code>. </p>''',
+ '''\
+<pre>
+if a%b == 0:
+ # b je delitelj števila a
+</pre>
+''']
+
+summing = ['''\
+<p>Če hočemo delitelje prišteti vsoti, moramo imeti vsoto nekje shranjeno.
+Torej potrebujemo spremenljivko.</p>''',
+ '''\
+<p>Nekako tako: </p>
+<pre>
+vsota = 0
+for ....
+ if ...
+ vsota += d # d deli izbrano število
+</pre>''']
+
+plan = ['''\
+<p>Gre za praktično enako nalogo, kot je bila prejšnja. Le na koncu
+moramo preveriti, če je vsota deliteljev enaka vnešenemu številu. </p>
+''']
+
+
+hint = {
+ 'input_clause': input_clause,
+
+ 'range_function': range_function,
+
+ 'printing': ['''\
+<p>Izpiši rezultat.</p>'''],
+
+ 'divisor': divisor,
+
+ 'final_hint': ['''\
+<p>Naloga rešena! <br>
+Podobno kot prejšnjo, lahko rešitev napišemo krajše: </p>
+<pre>
+n = int(input("Vpiši število: "))
+print(n == sum(i for i in range(1, n) if n % i == 0))
+</pre>'''],
+
+ 'summing': summing,
+
+ 'zero_division': [mod.general_msg['error_head'],
+ mod.general_msg['general_exception'],
+ '''\
+<p>Deljenje z nič ni dovoljeno!</p>''',
+ '''\
+<p>Računanje ostanka z operatorjem % je tudi deljenje.''']
+
+}
diff --git a/python/problems/lists_and_for/places/common.py b/python/problems/lists_and_for/places/common.py
new file mode 100644
index 0000000..66db7a3
--- /dev/null
+++ b/python/problems/lists_and_for/places/common.py
@@ -0,0 +1,49 @@
+# coding=utf-8
+
+import re
+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
+
+id = 218
+group = 'lists_and_for'
+number = 4
+visible = True
+
+solution = '''\
+xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2]
+
+mesta = []
+for i in range(len(xs)):
+ if xs[i] == 42:
+ mesta.append(i)
+print(mesta)
+'''
+
+hint_type = {
+ 'final_hint': Hint('final_hint')
+}
+
+def test(python, code):
+ test_in = [1]
+ n_correct = 0
+
+ passed = n_correct == len(test_in)
+ tin = None
+ tout = None
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, None)], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc: return exc
+
+ return None
diff --git a/python/problems/lists_and_for/places/en.py b/python/problems/lists_and_for/places/en.py
new file mode 100644
index 0000000..95b119f
--- /dev/null
+++ b/python/problems/lists_and_for/places/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 218
+name = 'Places'
+slug = 'Places'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/places/sl.py b/python/problems/lists_and_for/places/sl.py
new file mode 100644
index 0000000..716da30
--- /dev/null
+++ b/python/problems/lists_and_for/places/sl.py
@@ -0,0 +1,32 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 218
+name = 'Mesta'
+slug = 'Mesta'
+
+
+description = '''\
+<p>
+Program naj sestavi seznam vseh mest, na katerih se v podanem seznamu pojavi število 42.
+Za seznam iz prve naloge
+<pre>
+xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2]
+</pre>
+naj vaš program izpiše [0, 9], saj se število 42 pojavi na ničtem in devetem mestu (če začnemo šteti z 0).
+</p>'''
+
+plan = ['''\
+<p></p>
+''',
+ '''\
+<p></p>''']
+
+hint = {
+ 'final_hint': ['''\
+<p>Program je pravilen! <br>
+</p>
+'''],
+}
diff --git a/python/problems/lists_and_for/prefix/common.py b/python/problems/lists_and_for/prefix/common.py
new file mode 100644
index 0000000..cb8d706
--- /dev/null
+++ b/python/problems/lists_and_for/prefix/common.py
@@ -0,0 +1,48 @@
+# coding=utf-8
+
+import re
+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
+
+id = 221
+group = 'lists_and_for'
+number = 7
+visible = True
+
+solution = '''\
+s = input('Vpiši besedo: ')
+
+xs = []
+for i in range(len(s) + 1):
+ xs.append(s[:i])
+print(xs)
+'''
+
+hint_type = {
+ 'final_hint': Hint('final_hint')
+}
+
+def test(python, code):
+ test_in = [1]
+ n_correct = 0
+
+ passed = n_correct == len(test_in)
+ tin = None
+ tout = None
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, None)], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc: return exc
+
+ return None
diff --git a/python/problems/lists_and_for/prefix/en.py b/python/problems/lists_and_for/prefix/en.py
new file mode 100644
index 0000000..ea26765
--- /dev/null
+++ b/python/problems/lists_and_for/prefix/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 221
+name = 'Prefix'
+slug = 'Prefix'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/prefix/sl.py b/python/problems/lists_and_for/prefix/sl.py
new file mode 100644
index 0000000..0a3d391
--- /dev/null
+++ b/python/problems/lists_and_for/prefix/sl.py
@@ -0,0 +1,31 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 221
+name = 'Predpone'
+slug = 'Predpone'
+
+
+description = '''\
+<p>
+Uporabnika prosite, da vam zaupa besedo, nato pa sestavite in izpišite seznam vseh predpon te besede.
+<pre>
+Vpiši besedo: drevo
+['', 'd', 'dr', 'dre', 'drev', 'drevo']
+</pre>
+</p>'''
+
+plan = ['''\
+<p></p>
+''',
+ '''\
+<p></p>''']
+
+hint = {
+ 'final_hint': ['''\
+<p>Program je pravilen! <br>
+</p>
+'''],
+}
diff --git a/python/problems/lists_and_for/split_word/common.py b/python/problems/lists_and_for/split_word/common.py
new file mode 100644
index 0000000..0947b09
--- /dev/null
+++ b/python/problems/lists_and_for/split_word/common.py
@@ -0,0 +1,48 @@
+# coding=utf-8
+
+import re
+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
+
+id = 222
+group = 'lists_and_for'
+number = 8
+visible = True
+
+solution = '''\
+s = input('Vpiši besedo: ')
+
+xs = []
+for i in range(len(s) + 1):
+ xs.append((s[:i], s[i:]))
+print(x)
+'''
+
+hint_type = {
+ 'final_hint': Hint('final_hint')
+}
+
+def test(python, code):
+ test_in = [1]
+ n_correct = 0
+
+ passed = n_correct == len(test_in)
+ tin = None
+ tout = None
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, None)], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc: return exc
+
+ return None
diff --git a/python/problems/lists_and_for/split_word/en.py b/python/problems/lists_and_for/split_word/en.py
new file mode 100644
index 0000000..a6519d0
--- /dev/null
+++ b/python/problems/lists_and_for/split_word/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 222
+name = 'Split word'
+slug = 'Split word'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/split_word/sl.py b/python/problems/lists_and_for/split_word/sl.py
new file mode 100644
index 0000000..80ecfc4
--- /dev/null
+++ b/python/problems/lists_and_for/split_word/sl.py
@@ -0,0 +1,31 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 222
+name = 'Deli'
+slug = 'Deli'
+
+
+description = '''\
+<p>
+Program naj sestavi sezam vseh delitev podane besede.
+<pre>
+Vpiši besedo: gozd
+[('', 'gozd'), ('g', 'ozd'), ('go', 'zd'), ('goz', 'd'), ('gozd', '')]
+</pre>
+</p>'''
+
+plan = ['''\
+<p></p>
+''',
+ '''\
+<p></p>''']
+
+hint = {
+ 'final_hint': ['''\
+<p>Program je pravilen! <br>
+</p>
+'''],
+}
diff --git a/python/problems/lists_and_for/substrings/common.py b/python/problems/lists_and_for/substrings/common.py
new file mode 100644
index 0000000..32a3d4c
--- /dev/null
+++ b/python/problems/lists_and_for/substrings/common.py
@@ -0,0 +1,51 @@
+# coding=utf-8
+
+import re
+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
+
+id = 223
+group = 'lists_and_for'
+number = 9
+visible = True
+
+solution = '''\
+s = input('Vpiši besedo: ')
+
+xs = ['']
+# Zanka po dolžini podniza.
+for i in range(1, len(s) + 1):
+ # Zanka po začetku podniza.
+ for j in range(len(s) - i + 1):
+ xs.append(s[j:j + i])
+print(xs)
+'''
+
+hint_type = {
+ 'final_hint': Hint('final_hint')
+}
+
+def test(python, code):
+ test_in = [1]
+ n_correct = 0
+
+ passed = n_correct == len(test_in)
+ tin = None
+ tout = None
+ hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_in)}}]
+ if tin:
+ hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}})
+ if passed:
+ hints.append({'id': 'final_hint'})
+ return passed, hints
+
+def hint(python, code):
+ tokens = get_tokens(code)
+
+ # run one test first to see if there are any exceptions
+ answer = python(code=code, inputs=[(None, None)], timeout=1.0)
+ exc = get_exception_desc(answer[0][3])
+ if exc: return exc
+
+ return None
diff --git a/python/problems/lists_and_for/substrings/en.py b/python/problems/lists_and_for/substrings/en.py
new file mode 100644
index 0000000..053bee4
--- /dev/null
+++ b/python/problems/lists_and_for/substrings/en.py
@@ -0,0 +1,16 @@
+# coding=utf-8
+
+id = 223
+name = 'Substrings'
+slug = 'Substrings'
+
+description = '''\
+<p>(translation missing)</p>'''
+
+hint = {
+ 'plan': '''\
+<p>(translation missing)</p>''',
+
+ 'no_input_call': '''\
+<p>(translation missing)</p>''',
+}
diff --git a/python/problems/lists_and_for/substrings/sl.py b/python/problems/lists_and_for/substrings/sl.py
new file mode 100644
index 0000000..595aee8
--- /dev/null
+++ b/python/problems/lists_and_for/substrings/sl.py
@@ -0,0 +1,33 @@
+# coding=utf-8
+import server
+mod = server.problems.load_language('python', 'sl')
+
+
+id = 223
+name = 'Podnizi'
+slug = 'Podnizi'
+
+
+description = '''\
+<p>
+Program naj sestavi seznam vseh podnizov podane besede.
+<pre>
+Vpiši besedo: tema
+['', 't', 'e', 'm', 'a', 'te', 'em', 'ma', 'tem', 'ema', 'tema']
+</pre>
+Vrstni red naj bo točno tak kot ga prikazuje primer. Začnemo s praznim nizom,
+nato pridejo na vrsto podnizi dolžine ena, dva, tri, ...
+</p>'''
+
+plan = ['''\
+<p></p>
+''',
+ '''\
+<p></p>''']
+
+hint = {
+ 'final_hint': ['''\
+<p>Program je pravilen! <br>
+</p>
+'''],
+}