From 1f9f6de923e4b490c42a44d660b3e32dbe11426e Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 8 Oct 2015 11:17:16 +0200 Subject: Added final hint to contains_42. --- python/problems/lists_and_for/contains_42/common.py | 14 +++++++++++++- python/problems/lists_and_for/contains_42/sl.py | 21 +++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'python/problems/lists_and_for') 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 = ['''\

Pregledati bo treba vse elemente v seznamu xs''', '''\ -

Najlažje bo s for zanko. +

Najlažje bo s for zanko. ''', '''\ -

Poskusii naslednji dve vrstici:

+

Poskusi naslednji dve vrstici:

 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.

'''] if_clause = ['''\ -

Preveri, ali imamo število 42?

''', +

Preveri, ali imamo število 42?

''', '''\ -

Uporabi pogojni stavek if!

''', +

Uporabi pogojni stavek if!

''', '''\
 if x == 42:
@@ -57,7 +57,7 @@ videl42 = False
 

in jo tekom zanke ustrezno spremenimo.'''] plan = ['''\ -

Plan. Kako bi se tega lotil ročno? Nekako takole:

+

Kako bi se tega lotil ročno? Nekako takole:

 Za vsak element v seznamu
     Poglej, ali je 42?
@@ -82,6 +82,15 @@ hint = {
 

Izpiši rezultat.

'''], 'print_out_for': ['''\ -

Pazi, da izpišeš rezultat izven zanke!

'''] +

Pazi, da izpišeš rezultat izven zanke!

'''], + 'seen_42': seen_42, + + 'final_hint': ['''\ +

Program deluje pravilno!

'''], + + 'final_hint_nobreak': ['''\ +

Program deluje pravilno!
+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 break

'''], } -- cgit v1.2.1 From 45474b5c8cefa916aeb64e1c15a79f647a86d58c Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 8 Oct 2015 12:02:43 +0200 Subject: Added final hints. --- python/problems/lists_and_for/contains_42/sl.py | 6 ++++++ .../problems/lists_and_for/contains_string/common.py | 10 +++++++--- python/problems/lists_and_for/contains_string/sl.py | 20 +++++++++++++++++--- python/problems/lists_and_for/counting/sl.py | 17 ++++++++++++----- python/problems/lists_and_for/divisors/sl.py | 9 +++++---- 5 files changed, 47 insertions(+), 15 deletions(-) (limited to 'python/problems/lists_and_for') diff --git a/python/problems/lists_and_for/contains_42/sl.py b/python/problems/lists_and_for/contains_42/sl.py index 1a40549..245d346 100644 --- a/python/problems/lists_and_for/contains_42/sl.py +++ b/python/problems/lists_and_for/contains_42/sl.py @@ -93,4 +93,10 @@ hint = {

Program deluje pravilno!
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 break

'''], + + 'problematic_test_case': ['''\ +

Program ne dela pravilno!
+Poskusi xs = [%=testin%]
+pravilen rezultat: [%=testout%]

+'''], } diff --git a/python/problems/lists_and_for/contains_string/common.py b/python/problems/lists_and_for/contains_string/common.py index 29bc9f2..1f19d7f 100644 --- a/python/problems/lists_and_for/contains_string/common.py +++ b/python/problems/lists_and_for/contains_string/common.py @@ -25,7 +25,8 @@ 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'), + 'final_hint': Hint('final_hint') } def test(python, code): @@ -36,12 +37,12 @@ def test(python, code): [], ['Waldo']] test_out = [ + False, True, True, True, False, - True, - False + True ] n_correct = 0 @@ -69,6 +70,9 @@ 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)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints def hint(python, code): diff --git a/python/problems/lists_and_for/contains_string/sl.py b/python/problems/lists_and_for/contains_string/sl.py index d177463..49f0ed0 100644 --- a/python/problems/lists_and_for/contains_string/sl.py +++ b/python/problems/lists_and_for/contains_string/sl.py @@ -20,7 +20,7 @@ xs = ['foo', 'bar', 'baz', 'Waldo', 'foobar'] for_loop = ['''\

Pregledati bo treba vse elemente v seznamu xs''', '''\ -

Najlažje bo s for zanko. +

Najlažje bo s for zanko. ''', '''\

Poskusii naslednji dve vrstici:

@@ -43,7 +43,7 @@ if x == 'Waldo': plan = ['''\ -

Plan je enak kot pri prvi nalogi: +

Plan je enak kot pri prvi nalogi:

 Za vsak element v seznamu
     Poglej, ali je element enak 'Waldo'?
@@ -66,6 +66,20 @@ hint = {
 

Izpiši rezultat!

'''], 'print_out_for': ['''\ -

Pazi, da izpišeš rezultat izven zanke!

'''] +

Pazi, da izpišeš rezultat izven zanke!

'''], + + 'problematic_test_case': ['''\ +

Program ne dela pravilno!
+Poskusi xs = [%=testin%]
+pravilen rezultat: [%=testout%]

+'''], + + 'final_hint': ['''\ +

Program deluje pravilno!
+Nalogo lahko rešiš hitreje z operatorjem in

+
+xs = ['foo', 'bar', 'baz', 'Waldo', 'foobar']
+print('Waldo' in xs)
+
'''], } diff --git a/python/problems/lists_and_for/counting/sl.py b/python/problems/lists_and_for/counting/sl.py index 67dc323..c2fc820 100644 --- a/python/problems/lists_and_for/counting/sl.py +++ b/python/problems/lists_and_for/counting/sl.py @@ -80,11 +80,18 @@ hint = { 'print_out_for': ['''\

Pazi, da izpišeš rezultat izven zanke!

'''], - 'final_hint:': ['''\ -

Nalogo lahko rešiš bistveno hitreje, če poznaš metodo count

+ 'final_hint': ['''\ +

Program je pravilen!
+Nalogo lahko rešiš hitreje, če poznaš metodo count

- xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2]
- print('Število 42 se v seznamu pojavi', xs.count(42), 'krat.')
-
'''] +xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2] +print('Število 42 se v seznamu pojavi', xs.count(42), 'krat.') +
'''], + + 'problematic_test_case': ['''\ +

Program ne dela pravilno!
+Poskusi xs = [%=testin%]
+pravilen rezultat: [%=testout%]

+'''], } diff --git a/python/problems/lists_and_for/divisors/sl.py b/python/problems/lists_and_for/divisors/sl.py index 5ba36e1..cddeae8 100644 --- a/python/problems/lists_and_for/divisors/sl.py +++ b/python/problems/lists_and_for/divisors/sl.py @@ -74,15 +74,16 @@ hint = { 'last_number': ['''\

Število deli samega sebe!

'''], - 'final_hint:': ['''\ + 'final_hint': ['''\

Naloga rešena!

-

Dejansko ne potrebujemo pregledati vseh števil med 1 in n-1, +

Dejansko ne potrebujemo pregledati vseh števil med 1 in n-1, dovolj bo če gremo do kvadratnega korena od števila n:

-from math import sqrt
+from math import *
+
 n = int(input('Vnesi število: '))
-for i in range(1, sqrt(n)+1):
+for i in range(1, int(sqrt(n)+1)):
     if n % i == 0:
         print(i, n/i)
 
'''], -- cgit v1.2.1 From ce3b6703c153ba5c827996bfa8fd9bfa85fe2adb Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 8 Oct 2015 16:02:17 +0200 Subject: Remove unneeded id field from {en,sl}.py files --- python/problems/lists_and_for/contains_42/en.py | 1 - python/problems/lists_and_for/contains_42/sl.py | 1 - python/problems/lists_and_for/contains_string/en.py | 1 - python/problems/lists_and_for/contains_string/sl.py | 1 - python/problems/lists_and_for/counting/en.py | 1 - python/problems/lists_and_for/counting/sl.py | 1 - python/problems/lists_and_for/divisors/en.py | 1 - python/problems/lists_and_for/divisors/sl.py | 1 - 8 files changed, 8 deletions(-) (limited to 'python/problems/lists_and_for') diff --git a/python/problems/lists_and_for/contains_42/en.py b/python/problems/lists_and_for/contains_42/en.py index 805b37c..7794063 100644 --- a/python/problems/lists_and_for/contains_42/en.py +++ b/python/problems/lists_and_for/contains_42/en.py @@ -1,6 +1,5 @@ # coding=utf-8 -id = 193 name = 'Contains 42' slug = 'Contains 42' diff --git a/python/problems/lists_and_for/contains_42/sl.py b/python/problems/lists_and_for/contains_42/sl.py index 245d346..65353a7 100644 --- a/python/problems/lists_and_for/contains_42/sl.py +++ b/python/problems/lists_and_for/contains_42/sl.py @@ -3,7 +3,6 @@ import server mod = server.problems.load_language('python', 'sl') -id = 193 name = 'Vsebuje' slug = 'Vsebuje' diff --git a/python/problems/lists_and_for/contains_string/en.py b/python/problems/lists_and_for/contains_string/en.py index fa17867..b57be95 100644 --- a/python/problems/lists_and_for/contains_string/en.py +++ b/python/problems/lists_and_for/contains_string/en.py @@ -1,6 +1,5 @@ # coding=utf-8 -id = 194 name = 'Contains string' slug = 'Contains string' diff --git a/python/problems/lists_and_for/contains_string/sl.py b/python/problems/lists_and_for/contains_string/sl.py index 49f0ed0..7061c59 100644 --- a/python/problems/lists_and_for/contains_string/sl.py +++ b/python/problems/lists_and_for/contains_string/sl.py @@ -3,7 +3,6 @@ import server mod = server.problems.load_language('python', 'sl') -id = 194 name = 'Vsebuje niz' slug = 'Vsebuje niz' diff --git a/python/problems/lists_and_for/counting/en.py b/python/problems/lists_and_for/counting/en.py index 19568e3..223a611 100644 --- a/python/problems/lists_and_for/counting/en.py +++ b/python/problems/lists_and_for/counting/en.py @@ -1,6 +1,5 @@ # coding=utf-8 -id = 203 name = 'Counting' slug = 'Counting' diff --git a/python/problems/lists_and_for/counting/sl.py b/python/problems/lists_and_for/counting/sl.py index c2fc820..926d2c6 100644 --- a/python/problems/lists_and_for/counting/sl.py +++ b/python/problems/lists_and_for/counting/sl.py @@ -3,7 +3,6 @@ import server mod = server.problems.load_language('python', 'sl') -id = 203 name = 'Štej' slug = 'Štej' diff --git a/python/problems/lists_and_for/divisors/en.py b/python/problems/lists_and_for/divisors/en.py index e98e9a7..8f4dbeb 100644 --- a/python/problems/lists_and_for/divisors/en.py +++ b/python/problems/lists_and_for/divisors/en.py @@ -1,6 +1,5 @@ # coding=utf-8 -id = 204 name = 'Divisors' slug = 'Divisors' diff --git a/python/problems/lists_and_for/divisors/sl.py b/python/problems/lists_and_for/divisors/sl.py index cddeae8..11bfb40 100644 --- a/python/problems/lists_and_for/divisors/sl.py +++ b/python/problems/lists_and_for/divisors/sl.py @@ -3,7 +3,6 @@ import server mod = server.problems.load_language('python', 'sl') -id = 204 name = 'Delitelji' slug = 'Delitelji' -- cgit v1.2.1 From 3d0fde9ac8bc568845cfef8391ea0f9b0fe2f4e6 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 8 Oct 2015 16:13:35 +0200 Subject: Add language/group IDs and group numbers for Prolog --- python/problems/lists_and_for/common.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 python/problems/lists_and_for/common.py (limited to 'python/problems/lists_and_for') diff --git a/python/problems/lists_and_for/common.py b/python/problems/lists_and_for/common.py new file mode 100644 index 0000000..b490107 --- /dev/null +++ b/python/problems/lists_and_for/common.py @@ -0,0 +1 @@ +id = 16 -- cgit v1.2.1 From 84f3426c937d1bb9d44ba25a71706416fbb8b85d Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 9 Oct 2015 11:17:49 +0200 Subject: Added several new problems. They have no tests nor hints implemented. --- .../lists_and_for/calculator_polish/common.py | 70 +++++++++++++ .../problems/lists_and_for/calculator_polish/en.py | 16 +++ .../problems/lists_and_for/calculator_polish/sl.py | 61 +++++++++++ .../lists_and_for/contains_multiples/common.py | 49 +++++++++ .../lists_and_for/contains_multiples/en.py | 16 +++ .../lists_and_for/contains_multiples/sl.py | 29 ++++++ python/problems/lists_and_for/divisors/common.py | 4 +- python/problems/lists_and_for/divisors/sl.py | 2 +- .../problems/lists_and_for/divisors_sum/common.py | 111 ++++++++++++++++++++ python/problems/lists_and_for/divisors_sum/en.py | 16 +++ python/problems/lists_and_for/divisors_sum/sl.py | 101 ++++++++++++++++++ .../problems/lists_and_for/every_third/common.py | 50 +++++++++ python/problems/lists_and_for/every_third/en.py | 16 +++ python/problems/lists_and_for/every_third/sl.py | 35 +++++++ .../lists_and_for/perfect_numbers/common.py | 114 +++++++++++++++++++++ .../problems/lists_and_for/perfect_numbers/en.py | 16 +++ .../problems/lists_and_for/perfect_numbers/sl.py | 96 +++++++++++++++++ python/problems/lists_and_for/places/common.py | 49 +++++++++ python/problems/lists_and_for/places/en.py | 16 +++ python/problems/lists_and_for/places/sl.py | 32 ++++++ python/problems/lists_and_for/prefix/common.py | 48 +++++++++ python/problems/lists_and_for/prefix/en.py | 16 +++ python/problems/lists_and_for/prefix/sl.py | 31 ++++++ python/problems/lists_and_for/split_word/common.py | 48 +++++++++ python/problems/lists_and_for/split_word/en.py | 16 +++ python/problems/lists_and_for/split_word/sl.py | 31 ++++++ python/problems/lists_and_for/substrings/common.py | 51 +++++++++ python/problems/lists_and_for/substrings/en.py | 16 +++ python/problems/lists_and_for/substrings/sl.py | 33 ++++++ 29 files changed, 1186 insertions(+), 3 deletions(-) create mode 100644 python/problems/lists_and_for/calculator_polish/common.py create mode 100644 python/problems/lists_and_for/calculator_polish/en.py create mode 100644 python/problems/lists_and_for/calculator_polish/sl.py create mode 100644 python/problems/lists_and_for/contains_multiples/common.py create mode 100644 python/problems/lists_and_for/contains_multiples/en.py create mode 100644 python/problems/lists_and_for/contains_multiples/sl.py create mode 100644 python/problems/lists_and_for/divisors_sum/common.py create mode 100644 python/problems/lists_and_for/divisors_sum/en.py create mode 100644 python/problems/lists_and_for/divisors_sum/sl.py create mode 100644 python/problems/lists_and_for/every_third/common.py create mode 100644 python/problems/lists_and_for/every_third/en.py create mode 100644 python/problems/lists_and_for/every_third/sl.py create mode 100644 python/problems/lists_and_for/perfect_numbers/common.py create mode 100644 python/problems/lists_and_for/perfect_numbers/en.py create mode 100644 python/problems/lists_and_for/perfect_numbers/sl.py create mode 100644 python/problems/lists_and_for/places/common.py create mode 100644 python/problems/lists_and_for/places/en.py create mode 100644 python/problems/lists_and_for/places/sl.py create mode 100644 python/problems/lists_and_for/prefix/common.py create mode 100644 python/problems/lists_and_for/prefix/en.py create mode 100644 python/problems/lists_and_for/prefix/sl.py create mode 100644 python/problems/lists_and_for/split_word/common.py create mode 100644 python/problems/lists_and_for/split_word/en.py create mode 100644 python/problems/lists_and_for/split_word/sl.py create mode 100644 python/problems/lists_and_for/substrings/common.py create mode 100644 python/problems/lists_and_for/substrings/en.py create mode 100644 python/problems/lists_and_for/substrings/sl.py (limited to 'python/problems/lists_and_for') 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 = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

+V inverzni poljski ali postfiksni notaciji 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 (3 + 5) * 2 - 10 * (2 - 1) ali postfiksno 3 5 + 2 * 10 2 1 - * -: + +

    +
  • Beremo vhod do prve operacije.
  • +
  • 3 5 + ; izvede se seštevanje, tri elemente zamenja rezultat 8, beremo dalje.
  • +
  • 8 2 * ; rezultat je 16, beremo dalje.
  • +
  • 16 10 2 1 -; rezultat 1, beremo dalje.
  • +
  • 16 10 1 *; rezultat 10, beremo dalje.
  • +
  • 16 10 -; rezultat 6, beremo dalje.
  • +
  • 6; vhoda je konec zato se se računanje ustavi.
  • +
+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. +
+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:
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} 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 = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

+Napiši program, ki izpiše True, če se v seznamu števil pojavi večkratnik števila +42, sicer izpiše False. +Seznam xs definiraj na vrhu programa. +

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} 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 = {

Naloga rešena!

Dejansko ne potrebujemo pregledati vseh števil med 1 in n-1, - dovolj bo če gremo do kvadratnega korena od števila n:

+ dovolj bo če gremo do kvadratnega korena števila n:

 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 = '''\
+

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

Napiši program, ki izpiše vsoto vseh deliteljev števila, ki ga vnese uporabnik. +Med delitelji izpustite vnešeno število. Primer:

+
+>>> Vpiši število: 6
+Vsota deliteljev: 6
+
''' + +input_clause = ['''\ +Uporabi funkcijo input. +'''] + +range_function = ['''\ +Uporabi funkcijo range(a,b) +''', + '''\ +

Funkcija range(a, b) pripravi seznam števil od a do števila b-1. Poskusi!

''', + '''\ +

Z zanko for se sprehodi čez elemente seznama oz. v našem primeru +čez vsa števila od a do b-1.

+'''] + +divisor = ['''\ +

Operator % vrne ostanek pri deljenju.

''', + '''\ +
+>>> 5%3
+2
+>>> 17%8
+1
+
''', + '''\ +

Če je ostanek pri deljenju števila a s številom b enak 0, potem b +deli število a.

''', + '''\ +
+if a%b == 0:
+    # b je delitelj števila a
+
+'''] + +summing = ['''\ +

Če hočemo delitelje prišteti vsoti, moramo imeti vsoto nekje shranjeno. +Torej potrebujemo spremenljivko.

''', + '''\ +

Nekako tako:

+
+vsota = 0
+for ....
+    if ...
+        vsota += d # d deli izbrano število
+
'''] + +plan = ['''\ +

Plan bo podoben kot v prejšnji naloge, kjer smo delitelje izpisali. +Tokrat delitelja ne izpišemo, ampak ga prištejemo vsoti.

+''', + summing] + + +hint = { + 'input_clause': input_clause, + + 'range_function': range_function, + + 'printing': ['''\ +

Izpiši rezultat.

'''], + + 'divisor': divisor, + + 'last_number': ['''\ +

Tokrat med delitelji ne upoštevamo vnešenega števila!

'''], + + 'final_hint': ['''\ +

Naloga rešena!
+Nakoč bomo znali to napisati krajše:

+
+n = int(input("Vpiši število: "))
+print(sum(i for i in range(1, n) if n % i == 0))
+
'''], + + 'summing': summing, + + 'zero_division': [mod.general_msg['error_head'], + mod.general_msg['general_exception'], + '''\ +

Deljenje z nič ni dovoljeno!

''', + '''\ +

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 = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

+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 +

+xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2]
+
+in (v tem primeru) izpiše +
+[4, 12, 11]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} 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 = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

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.

''' + +input_clause = ['''\ +Uporabi funkcijo input. +'''] + +range_function = ['''\ +Uporabi funkcijo range(a,b) +''', + '''\ +

Funkcija range(a, b) pripravi seznam števil od a do števila b-1. Poskusi!

''', + '''\ +

Z zanko for se sprehodi čez elemente seznama oz. v našem primeru +čez vsa števila od a do b-1.

+'''] + +divisor = ['''\ +

Operator % vrne ostanek pri deljenju.

''', + '''\ +
+>>> 5%3
+2
+>>> 17%8
+1
+
''', + '''\ +

Če je ostanek pri deljenju števila a s številom b enak 0, potem b +deli število a.

''', + '''\ +
+if a%b == 0:
+    # b je delitelj števila a
+
+'''] + +summing = ['''\ +

Če hočemo delitelje prišteti vsoti, moramo imeti vsoto nekje shranjeno. +Torej potrebujemo spremenljivko.

''', + '''\ +

Nekako tako:

+
+vsota = 0
+for ....
+    if ...
+        vsota += d # d deli izbrano število
+
'''] + +plan = ['''\ +

Gre za praktično enako nalogo, kot je bila prejšnja. Le na koncu +moramo preveriti, če je vsota deliteljev enaka vnešenemu številu.

+'''] + + +hint = { + 'input_clause': input_clause, + + 'range_function': range_function, + + 'printing': ['''\ +

Izpiši rezultat.

'''], + + 'divisor': divisor, + + 'final_hint': ['''\ +

Naloga rešena!
+Podobno kot prejšnjo, lahko rešitev napišemo krajše:

+
+n = int(input("Vpiši število: "))
+print(n == sum(i for i in range(1, n) if n % i == 0))
+
'''], + + 'summing': summing, + + 'zero_division': [mod.general_msg['error_head'], + mod.general_msg['general_exception'], + '''\ +

Deljenje z nič ni dovoljeno!

''', + '''\ +

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 = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

+Program naj sestavi seznam vseh mest, na katerih se v podanem seznamu pojavi število 42. +Za seznam iz prve naloge +

+xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2]
+
+naj vaš program izpiše [0, 9], saj se število 42 pojavi na ničtem in devetem mestu (če začnemo šteti z 0). +

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} 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 = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

+Uporabnika prosite, da vam zaupa besedo, nato pa sestavite in izpišite seznam vseh predpon te besede. +

+Vpiši besedo: drevo
+['', 'd', 'dr', 'dre', 'drev', 'drevo']
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} 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 = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

+Program naj sestavi sezam vseh delitev podane besede. +

+Vpiši besedo: gozd
+[('', 'gozd'), ('g', 'ozd'), ('go', 'zd'), ('goz', 'd'), ('gozd', '')]
+
+

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} 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 = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} 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 = '''\ +

+Program naj sestavi seznam vseh podnizov podane besede. +

+Vpiši besedo: tema
+['', 't', 'e', 'm', 'a', 'te', 'em', 'ma', 'tem', 'ema', 'tema']
+
+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, ... +

''' + +plan = ['''\ +

+''', + '''\ +

'''] + +hint = { + 'final_hint': ['''\ +

Program je pravilen!
+

+'''], +} -- cgit v1.2.1 From 95e107bf9e6a288969e4a83aee1a7062990f3b67 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 9 Oct 2015 16:35:23 +0200 Subject: Fixed testing for most problems. --- .../lists_and_for/calculator_polish/common.py | 33 ++++++++++++++++-- python/problems/lists_and_for/common.py | 1 + .../lists_and_for/contains_multiples/common.py | 40 ++++++++++++++++++++-- python/problems/lists_and_for/divisors/common.py | 2 +- .../problems/lists_and_for/divisors_sum/common.py | 2 +- .../problems/lists_and_for/every_third/common.py | 34 ++++++++++++++++-- .../lists_and_for/perfect_numbers/common.py | 2 +- python/problems/lists_and_for/places/common.py | 38 ++++++++++++++++++-- python/problems/lists_and_for/prefix/common.py | 25 ++++++++++++-- python/problems/lists_and_for/split_word/common.py | 26 +++++++++++--- python/problems/lists_and_for/substrings/common.py | 24 +++++++++++-- 11 files changed, 202 insertions(+), 25 deletions(-) (limited to 'python/problems/lists_and_for') diff --git a/python/problems/lists_and_for/calculator_polish/common.py b/python/problems/lists_and_for/calculator_polish/common.py index d08f19c..7ea25ce 100644 --- a/python/problems/lists_and_for/calculator_polish/common.py +++ b/python/problems/lists_and_for/calculator_polish/common.py @@ -46,12 +46,39 @@ hint_type = { } def test(python, code): - test_in = [1] + in_out = [ + (['6 3 +'], [9]), + (['6 3 -'], [3]), + (['6 3 /'], [2]), + (['7 3 /'], [2]), + (['6 3 *'], [18]), + (['6 3 %'], [0]), + (['1 2 +', '2 3 +', '1 2 3 4 5 * * * *'], [3, 5, 120]), + (['1 2 + 3 +'], [6]), + (['1 2 3 + +'], [6]), + (['1 2 + 3 4 + *'], [21]), + (['1 2 3 * 4 + +'], [11]), + (['3 5 + 2 * 10 2 1 - * -'], [6]), + (['11 22 33 * * 7 + 2 / 100 % 1 2 - -'], [97]), + ] + + test_in = [(None, '\n'.join(s[0])+'\n') for s in in_out] + test_out = [s[1] for s in in_out] + # 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 = 0 + tin = None + for i, (output, correct) in enumerate(zip(outputs, test_out)): + if all(string_almost_equal(output, c, prec=2) for c in correct): + n_correct += 1 + else: + tin = test_in[i][1] + tout = correct 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)}}) diff --git a/python/problems/lists_and_for/common.py b/python/problems/lists_and_for/common.py index b490107..fe6aa94 100644 --- a/python/problems/lists_and_for/common.py +++ b/python/problems/lists_and_for/common.py @@ -1 +1,2 @@ id = 16 +number = 3 \ No newline at end of file diff --git a/python/problems/lists_and_for/contains_multiples/common.py b/python/problems/lists_and_for/contains_multiples/common.py index 8bdcc36..4712106 100644 --- a/python/problems/lists_and_for/contains_multiples/common.py +++ b/python/problems/lists_and_for/contains_multiples/common.py @@ -25,12 +25,46 @@ hint_type = { } def test(python, code): - test_in = [1] + in_out = [ + ([], False), + ([0], True), + ([42], True), + ([42 * 43], True), + ([4, 2], False), + ([42, 42], True), + ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1], False), + ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1, -42], True), + ([1, 2, 3, 4, 5, 42 * 3, 5, 4, 3, 2, 1], True), + ([1, 2, 42, 4, 5, 42 * 5, 5, 4, 42 * 3, 2, 1], True), + ([42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2], True) + ] + + + test_in = [t[0] for t in in_out] + test_out = [t[1] for t in in_out] + n_correct = 0 + tin = None + for xs_i, xs in enumerate(test_in): + # change code to contain new xs instead of the one + # given by user + tcode = re.sub(r'^xs\s*=\s*\[.*?\]', + 'xs = ' + str(xs), + code, + flags = re.DOTALL | re.MULTILINE) + # use python session to call tcode + answers = python(code=tcode, inputs=[(None, None)], timeout=1.0) + output = answers[0][1] + + if str(test_out[xs_i]) in output and \ + str((not test_out[xs_i])) not in output: + n_correct += 1 + else: + tin = test_in[xs_i] + tout = test_out[xs_i] 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)}}) diff --git a/python/problems/lists_and_for/divisors/common.py b/python/problems/lists_and_for/divisors/common.py index f9334be..89092eb 100644 --- a/python/problems/lists_and_for/divisors/common.py +++ b/python/problems/lists_and_for/divisors/common.py @@ -8,7 +8,7 @@ from server.hints import Hint id = 204 group = 'lists_and_for' number = 20 -visible = False +visible = True solution = '''\ n = int(input('Vnesi število: ')) diff --git a/python/problems/lists_and_for/divisors_sum/common.py b/python/problems/lists_and_for/divisors_sum/common.py index 651f657..c557278 100644 --- a/python/problems/lists_and_for/divisors_sum/common.py +++ b/python/problems/lists_and_for/divisors_sum/common.py @@ -8,7 +8,7 @@ from server.hints import Hint id = 216 group = 'lists_and_for' number = 21 -visible = False +visible = True solution = '''\ n = int(input('Vnesi število: ')) diff --git a/python/problems/lists_and_for/every_third/common.py b/python/problems/lists_and_for/every_third/common.py index 9c27446..6f42663 100644 --- a/python/problems/lists_and_for/every_third/common.py +++ b/python/problems/lists_and_for/every_third/common.py @@ -26,12 +26,40 @@ hint_type = { } def test(python, code): - test_in = [1] + in_out = [ + ([], []), + ([0], []), + ([0, 1], []), + ([0, 1, 2], [2]), + ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1], [3, 5, 2]), + ([42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2], [4, 12, 11]), + (list(range(15)), [2, 5, 8, 11, 14]) + ] + + test_in = [t[0] for t in in_out] + test_out = [t[1] for t in in_out] + n_correct = 0 + tin = None + for xs_i, xs in enumerate(test_in): + # change code to contain new xs instead of the one + # given by user + tcode = re.sub(r'^xs\s*=\s*\[.*?\]', + 'xs = ' + str(xs), + code, + flags = re.DOTALL | re.MULTILINE) + # use python session to call tcode + answers = python(code=tcode, inputs=[(None, None)], timeout=1.0) + output = answers[0][1] + + if str(test_out[xs_i]) in output: + n_correct += 1 + else: + tin = test_in[xs_i] + tout = test_out[xs_i] 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)}}) diff --git a/python/problems/lists_and_for/perfect_numbers/common.py b/python/problems/lists_and_for/perfect_numbers/common.py index c1c7645..2628fab 100644 --- a/python/problems/lists_and_for/perfect_numbers/common.py +++ b/python/problems/lists_and_for/perfect_numbers/common.py @@ -8,7 +8,7 @@ from server.hints import Hint id = 217 group = 'lists_and_for' number = 22 -visible = False +visible = True solution = '''\ n = int(input('Vnesi število: ')) diff --git a/python/problems/lists_and_for/places/common.py b/python/problems/lists_and_for/places/common.py index 66db7a3..0a90771 100644 --- a/python/problems/lists_and_for/places/common.py +++ b/python/problems/lists_and_for/places/common.py @@ -25,12 +25,44 @@ hint_type = { } def test(python, code): - test_in = [1] + in_out = [ + ([], []), + ([0], []), + ([42], [0]), + ([4, 2], []), + ([42, 42], [0, 1]), + ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1], []), + ([1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 42], [10]), + ([1, 2, 3, 4, 5, 42, 5, 4, 3, 2, 1], [5]), + ([1, 2, 42, 4, 5, 42, 5, 4, 42, 2, 1], [2, 5, 8]), + ([42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2], [0, 9]), + ([42] * 10, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), + ] + + test_in = [t[0] for t in in_out] + test_out = [t[1] for t in in_out] + n_correct = 0 + tin = None + for xs_i, xs in enumerate(test_in): + # change code to contain new xs instead of the one + # given by user + tcode = re.sub(r'^xs\s*=\s*\[.*?\]', + 'xs = ' + str(xs), + code, + flags = re.DOTALL | re.MULTILINE) + + # use python session to call tcode + answers = python(code=tcode, inputs=[(None, None)], timeout=1.0) + output = answers[0][1] + + if str(test_out[xs_i]) in output: + n_correct += 1 + else: + tin = test_in[xs_i] + tout = test_out[xs_i] 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)}}) diff --git a/python/problems/lists_and_for/prefix/common.py b/python/problems/lists_and_for/prefix/common.py index cb8d706..1198e65 100644 --- a/python/problems/lists_and_for/prefix/common.py +++ b/python/problems/lists_and_for/prefix/common.py @@ -24,12 +24,29 @@ hint_type = { } def test(python, code): - test_in = [1] + in_out = [ + ('a', ['', 'a']), + ('ab', ['', 'a', 'ab']), + ('abc', ['', 'a', 'ab', 'abc']), + ('drevo', ['', 'd', 'dr', 'dre', 'drev', 'drevo']), + ] + + test_in = [(None, s[0]+'\n') for s in in_out] + test_out = [str(s[1]) for s in in_out] + # 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 = 0 + tin = None + for i, (output, correct) in enumerate(zip(outputs, test_out)): + if correct in output: + n_correct += 1 + else: + tin = test_in[i][1] + tout = correct 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)}}) @@ -46,3 +63,5 @@ def hint(python, code): if exc: return exc return None + + diff --git a/python/problems/lists_and_for/split_word/common.py b/python/problems/lists_and_for/split_word/common.py index 0947b09..0f5c5b9 100644 --- a/python/problems/lists_and_for/split_word/common.py +++ b/python/problems/lists_and_for/split_word/common.py @@ -16,7 +16,7 @@ s = input('Vpiši besedo: ') xs = [] for i in range(len(s) + 1): xs.append((s[:i], s[i:])) -print(x) +print(xs) ''' hint_type = { @@ -24,12 +24,30 @@ hint_type = { } def test(python, code): - test_in = [1] + in_out = [ + ('a', [('', 'a'), ('a', '')]), + ('ab', [('', 'ab'), ('a', 'b'), ('ab', '')]), + ('abc', [('', 'abc'), ('a', 'bc'), ('ab', 'c'), ('abc', '')]), + ('gozd', [('', 'gozd'), ('g', 'ozd'), ('go', 'zd'), ('goz', 'd'), ('gozd', '')]), + ] + + test_in = [(None, s[0]+'\n') for s in in_out] + test_out = [str(s[1]) for s in in_out] + # 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 = 0 + tin = None + for i, (output, correct) in enumerate(zip(outputs, test_out)): + if correct in output: + n_correct += 1 + else: + tin = test_in[i][1] + tout = correct 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)}}) diff --git a/python/problems/lists_and_for/substrings/common.py b/python/problems/lists_and_for/substrings/common.py index 32a3d4c..bdc356a 100644 --- a/python/problems/lists_and_for/substrings/common.py +++ b/python/problems/lists_and_for/substrings/common.py @@ -27,12 +27,30 @@ hint_type = { } def test(python, code): - test_in = [1] + in_out = [ + ('a', ['', 'a']), + ('ab', ['', 'a', 'b', 'ab']), + ('abc', ['', 'a', 'b', 'c', 'ab', 'bc', 'abc']), + ('tema', ['', 't', 'e', 'm', 'a', 'te', 'em', 'ma', 'tem', 'ema', 'tema']), + ] + + test_in = [(None, s[0]+'\n') for s in in_out] + test_out = [str(s[1]) for s in in_out] + # 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 = 0 + tin = None + for i, (output, correct) in enumerate(zip(outputs, test_out)): + if correct in output: + n_correct += 1 + else: + tin = test_in[i][1] + tout = correct 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)}}) -- cgit v1.2.1 From 6e281624b9a0ae29f1f1862f9d581b219ba3b95a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 12 Oct 2015 11:46:08 +0200 Subject: Remove group attribute from problem common.py files --- python/problems/lists_and_for/calculator_polish/common.py | 1 - python/problems/lists_and_for/contains_42/common.py | 1 - python/problems/lists_and_for/contains_multiples/common.py | 1 - python/problems/lists_and_for/contains_string/common.py | 1 - python/problems/lists_and_for/counting/common.py | 1 - python/problems/lists_and_for/divisors/common.py | 1 - python/problems/lists_and_for/divisors_sum/common.py | 1 - python/problems/lists_and_for/every_third/common.py | 1 - python/problems/lists_and_for/perfect_numbers/common.py | 1 - python/problems/lists_and_for/places/common.py | 1 - python/problems/lists_and_for/prefix/common.py | 1 - python/problems/lists_and_for/split_word/common.py | 1 - python/problems/lists_and_for/substrings/common.py | 1 - 13 files changed, 13 deletions(-) (limited to 'python/problems/lists_and_for') diff --git a/python/problems/lists_and_for/calculator_polish/common.py b/python/problems/lists_and_for/calculator_polish/common.py index 7ea25ce..cb89a50 100644 --- a/python/problems/lists_and_for/calculator_polish/common.py +++ b/python/problems/lists_and_for/calculator_polish/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 224 -group = 'lists_and_for' number = 10 visible = True diff --git a/python/problems/lists_and_for/contains_42/common.py b/python/problems/lists_and_for/contains_42/common.py index d4c4af8..fb2089e 100644 --- a/python/problems/lists_and_for/contains_42/common.py +++ b/python/problems/lists_and_for/contains_42/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 193 -group = 'lists_and_for' number = 1 visible = True diff --git a/python/problems/lists_and_for/contains_multiples/common.py b/python/problems/lists_and_for/contains_multiples/common.py index 4712106..59a5743 100644 --- a/python/problems/lists_and_for/contains_multiples/common.py +++ b/python/problems/lists_and_for/contains_multiples/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 219 -group = 'lists_and_for' number = 5 visible = True diff --git a/python/problems/lists_and_for/contains_string/common.py b/python/problems/lists_and_for/contains_string/common.py index 1f19d7f..62fef4e 100644 --- a/python/problems/lists_and_for/contains_string/common.py +++ b/python/problems/lists_and_for/contains_string/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 194 -group = 'lists_and_for' number = 2 visible = True diff --git a/python/problems/lists_and_for/counting/common.py b/python/problems/lists_and_for/counting/common.py index 2d59182..73d0071 100644 --- a/python/problems/lists_and_for/counting/common.py +++ b/python/problems/lists_and_for/counting/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 203 -group = 'lists_and_for' number = 3 visible = True diff --git a/python/problems/lists_and_for/divisors/common.py b/python/problems/lists_and_for/divisors/common.py index 89092eb..a99246b 100644 --- a/python/problems/lists_and_for/divisors/common.py +++ b/python/problems/lists_and_for/divisors/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 204 -group = 'lists_and_for' number = 20 visible = True diff --git a/python/problems/lists_and_for/divisors_sum/common.py b/python/problems/lists_and_for/divisors_sum/common.py index c557278..1d11410 100644 --- a/python/problems/lists_and_for/divisors_sum/common.py +++ b/python/problems/lists_and_for/divisors_sum/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 216 -group = 'lists_and_for' number = 21 visible = True diff --git a/python/problems/lists_and_for/every_third/common.py b/python/problems/lists_and_for/every_third/common.py index 6f42663..2d5b907 100644 --- a/python/problems/lists_and_for/every_third/common.py +++ b/python/problems/lists_and_for/every_third/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 220 -group = 'lists_and_for' number = 6 visible = True diff --git a/python/problems/lists_and_for/perfect_numbers/common.py b/python/problems/lists_and_for/perfect_numbers/common.py index 2628fab..9a48967 100644 --- a/python/problems/lists_and_for/perfect_numbers/common.py +++ b/python/problems/lists_and_for/perfect_numbers/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 217 -group = 'lists_and_for' number = 22 visible = True diff --git a/python/problems/lists_and_for/places/common.py b/python/problems/lists_and_for/places/common.py index 0a90771..e7d1adf 100644 --- a/python/problems/lists_and_for/places/common.py +++ b/python/problems/lists_and_for/places/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 218 -group = 'lists_and_for' number = 4 visible = True diff --git a/python/problems/lists_and_for/prefix/common.py b/python/problems/lists_and_for/prefix/common.py index 1198e65..cd649af 100644 --- a/python/problems/lists_and_for/prefix/common.py +++ b/python/problems/lists_and_for/prefix/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 221 -group = 'lists_and_for' number = 7 visible = True diff --git a/python/problems/lists_and_for/split_word/common.py b/python/problems/lists_and_for/split_word/common.py index 0f5c5b9..6031b19 100644 --- a/python/problems/lists_and_for/split_word/common.py +++ b/python/problems/lists_and_for/split_word/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 222 -group = 'lists_and_for' number = 8 visible = True diff --git a/python/problems/lists_and_for/substrings/common.py b/python/problems/lists_and_for/substrings/common.py index bdc356a..8128797 100644 --- a/python/problems/lists_and_for/substrings/common.py +++ b/python/problems/lists_and_for/substrings/common.py @@ -6,7 +6,6 @@ from python.util import has_token_sequence, string_almost_equal, \ from server.hints import Hint id = 223 -group = 'lists_and_for' number = 9 visible = True -- cgit v1.2.1 From fbe617ad061df25775c3e3ade00993a9090c9ef2 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 12 Oct 2015 13:07:03 +0200 Subject: Added plan to problem "Places". --- python/problems/lists_and_for/places/sl.py | 50 ++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'python/problems/lists_and_for') diff --git a/python/problems/lists_and_for/places/sl.py b/python/problems/lists_and_for/places/sl.py index 716da30..d66e17d 100644 --- a/python/problems/lists_and_for/places/sl.py +++ b/python/problems/lists_and_for/places/sl.py @@ -18,11 +18,57 @@ xs = [42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2] naj vaš program izpiše [0, 9], saj se število 42 pojavi na ničtem in devetem mestu (če začnemo šteti z 0).

''' +empty_list = ['''\ +

Nov, prazen seznam ustvarimo s stavkom:

+
+s = []
+
+'''] + +enumerate_function = ['''\ +

Z uporabo funkcije enumerate boste najlažje dostopali do +indeksov seznama. +

+''', + '''\ +
+for index, val in enumerate(xs):
+    print index, v
+
''', + '''\ +

V zgornji forzanki se v spremenljivko val zapiše +trenutni element v seznamu xs, v spremenljivki indeks +pa je zapisano mesto oz. indeks trenutnega elementa.

'''] + +append_method = [ + '''\ +

V seznam dodamo nov element z metodo append.

''', + '''\ +

Poskusi:

+
+s = []
+s.append(3)
+s.append(5)
+print (s)
+
'''] + plan = ['''\ -

+

S for zanko pojdi čez seznam. Ko naletiš na 42, dodaj mesto trenutnega elementa +v nov seznam.

''', '''\ -

'''] +

+

+Ustvari prazen seznam mest
+Za vsak element v seznamu
+    Ali je 42?
+        Če je, dodaj trenutno mesto v seznam mest
+Izpiši seznam mest
+
+

''', + empty_list, + enumerate_function, + append_method] hint = { 'final_hint': ['''\ -- cgit v1.2.1 From 5a01c2bb184152c6ccc3c536e9b857d247bc55ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mo=C5=BEina?= Date: Mon, 12 Oct 2015 14:09:22 +0200 Subject: Added plans to problems. --- .../lists_and_for/contains_multiples/sl.py | 7 ++-- python/problems/lists_and_for/every_third/sl.py | 49 +++++++++++++++++++++- python/problems/lists_and_for/places/sl.py | 5 +-- 3 files changed, 53 insertions(+), 8 deletions(-) (limited to 'python/problems/lists_and_for') diff --git a/python/problems/lists_and_for/contains_multiples/sl.py b/python/problems/lists_and_for/contains_multiples/sl.py index ae4c845..7345370 100644 --- a/python/problems/lists_and_for/contains_multiples/sl.py +++ b/python/problems/lists_and_for/contains_multiples/sl.py @@ -15,11 +15,12 @@ Napiši program, ki izpiše True, če se v seznamu števil pojavi v Seznam xs definiraj na vrhu programa.

''' + + plan = ['''\ -

+

Popolnoma enaka naloga kot naloga "Vsebuje", le pri pogoju poglej, ali je število deljivo z 42.

''', - '''\ -

'''] + mod.general_msg["modulo"]] hint = { 'final_hint': ['''\ diff --git a/python/problems/lists_and_for/every_third/sl.py b/python/problems/lists_and_for/every_third/sl.py index 3bac8a3..50b4520 100644 --- a/python/problems/lists_and_for/every_third/sl.py +++ b/python/problems/lists_and_for/every_third/sl.py @@ -21,11 +21,56 @@ in (v tem primeru) izpiše

''' +empty_list = ['''\ +

Nov, prazen seznam ustvarimo s stavkom:

+
+s = []
+
+'''] + +enumerate_function = ['''\ +

Uporabi funkcijo enumerate. +

+''', + '''\ +
+for index, val in enumerate(xs):
+    print index, v
+
''', + '''\ +

V zgornji forzanki se v spremenljivko val zapiše +trenutni element v seznamu xs, v spremenljivki indeks +pa je zapisano mesto oz. indeks trenutnega elementa.

'''] + +append_method = [ + '''\ +

V seznam dodamo nov element z metodo append.

''', + '''\ +

Poskusi:

+
+s = []
+s.append(3)
+s.append(5)
+print (s)
+
'''] + plan = ['''\ -

+

S for zanko pojdi čez seznam. V novi seznam dodaj vsak tretji element.

''', '''\ -

'''] +

+

+Ustvari prazen seznam mest
+Za vsak element v seznamu
+    Ali je (mesto elementa + 1) deljivo s 3?
+        Če je, dodaj trenutno mesto v seznam mest
+Izpiši seznam mest
+
+

''', + empty_list, + enumerate_function, + mod.general_msg["modulo"], + append_method] hint = { 'final_hint': ['''\ diff --git a/python/problems/lists_and_for/places/sl.py b/python/problems/lists_and_for/places/sl.py index d66e17d..5a435a0 100644 --- a/python/problems/lists_and_for/places/sl.py +++ b/python/problems/lists_and_for/places/sl.py @@ -26,8 +26,7 @@ s = [] '''] enumerate_function = ['''\ -

Z uporabo funkcije enumerate boste najlažje dostopali do -indeksov seznama. +

Uporabi funkcijo enumerate.

''', '''\ @@ -53,7 +52,7 @@ print (s)
'''] plan = ['''\ -

S for zanko pojdi čez seznam. Ko naletiš na 42, dodaj mesto trenutnega elementa +

S for zanko pojdi čez seznam. Ko naletiš na 42, dodaj mesto trenutnega elementa v nov seznam.

''', '''\ -- cgit v1.2.1