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. --- python/problems/functions/assign_numbers/common.py | 47 +++++++++ python/problems/functions/assign_numbers/en.py | 16 +++ python/problems/functions/assign_numbers/sl.py | 34 ++++++ .../problems/functions/body_mass_index/common.py | 47 +++++++++ python/problems/functions/body_mass_index/en.py | 16 +++ python/problems/functions/body_mass_index/sl.py | 35 +++++++ .../problems/functions/body_mass_index_2/common.py | 47 +++++++++ python/problems/functions/body_mass_index_2/en.py | 16 +++ python/problems/functions/body_mass_index_2/sl.py | 34 ++++++ python/problems/functions/divisors/common.py | 46 +++++++++ python/problems/functions/divisors/en.py | 16 +++ python/problems/functions/divisors/sl.py | 26 +++++ python/problems/functions/divisors_sum/common.py | 48 +++++++++ python/problems/functions/divisors_sum/en.py | 16 +++ python/problems/functions/divisors_sum/sl.py | 27 +++++ .../problems/functions/friendly_numbers/common.py | 53 ++++++++++ python/problems/functions/friendly_numbers/en.py | 16 +++ python/problems/functions/friendly_numbers/sl.py | 37 +++++++ .../problems/functions/greatest_absolutist/sl.py | 2 +- python/problems/functions/palindrome/common.py | 44 ++++++++ python/problems/functions/palindrome/en.py | 16 +++ python/problems/functions/palindrome/sl.py | 33 ++++++ .../functions/palindromic_numbers/common.py | 49 +++++++++ .../problems/functions/palindromic_numbers/en.py | 16 +++ .../problems/functions/palindromic_numbers/sl.py | 31 ++++++ .../problems/functions/perfect_numbers/common.py | 51 +++++++++ python/problems/functions/perfect_numbers/en.py | 16 +++ python/problems/functions/perfect_numbers/sl.py | 30 ++++++ python/problems/functions/prime_numbers/common.py | 49 +++++++++ python/problems/functions/prime_numbers/en.py | 16 +++ python/problems/functions/prime_numbers/sl.py | 27 +++++ .../problems/functions_and_modules/all/common.py | 47 +++++++++ python/problems/functions_and_modules/all/en.py | 16 +++ python/problems/functions_and_modules/all/sl.py | 40 ++++++++ .../problems/functions_and_modules/any/common.py | 47 +++++++++ python/problems/functions_and_modules/any/en.py | 16 +++ python/problems/functions_and_modules/any/sl.py | 34 ++++++ .../functions_and_modules/caesar_cipher/common.py | 52 ++++++++++ .../functions_and_modules/caesar_cipher/en.py | 16 +++ .../functions_and_modules/caesar_cipher/sl.py | 35 +++++++ .../functions_and_modules/dominoes/common.py | 47 +++++++++ .../problems/functions_and_modules/dominoes/en.py | 16 +++ .../problems/functions_and_modules/dominoes/sl.py | 29 ++++++ python/problems/functions_and_modules/en.py | 3 + .../largest_sublist/common.py | 53 ++++++++++ .../functions_and_modules/largest_sublist/en.py | 16 +++ .../functions_and_modules/largest_sublist/sl.py | 33 ++++++ .../functions_and_modules/lists_sum/common.py | 50 +++++++++ .../problems/functions_and_modules/lists_sum/en.py | 16 +++ .../problems/functions_and_modules/lists_sum/sl.py | 35 +++++++ .../functions_and_modules/longest_word/common.py | 48 +++++++++ .../functions_and_modules/longest_word/en.py | 16 +++ .../functions_and_modules/longest_word/sl.py | 30 ++++++ .../problems/functions_and_modules/map/common.py | 47 +++++++++ python/problems/functions_and_modules/map/en.py | 16 +++ python/problems/functions_and_modules/map/sl.py | 34 ++++++ .../multiplicative_range/common.py | 48 +++++++++ .../multiplicative_range/en.py | 16 +++ .../multiplicative_range/sl.py | 32 ++++++ .../functions_and_modules/similarity/common.py | 48 +++++++++ .../functions_and_modules/similarity/en.py | 16 +++ .../functions_and_modules/similarity/sl.py | 39 +++++++ python/problems/functions_and_modules/sl.py | 3 + .../suspicious_words/common.py | 48 +++++++++ .../functions_and_modules/suspicious_words/en.py | 16 +++ .../functions_and_modules/suspicious_words/sl.py | 32 ++++++ .../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 ++++++ .../problems/while_and_if/checking_account/en.py | 4 +- .../while_and_if/consumers_anonymous/en.py | 4 +- 97 files changed, 3236 insertions(+), 8 deletions(-) create mode 100644 python/problems/functions/assign_numbers/common.py create mode 100644 python/problems/functions/assign_numbers/en.py create mode 100644 python/problems/functions/assign_numbers/sl.py create mode 100644 python/problems/functions/body_mass_index/common.py create mode 100644 python/problems/functions/body_mass_index/en.py create mode 100644 python/problems/functions/body_mass_index/sl.py create mode 100644 python/problems/functions/body_mass_index_2/common.py create mode 100644 python/problems/functions/body_mass_index_2/en.py create mode 100644 python/problems/functions/body_mass_index_2/sl.py create mode 100644 python/problems/functions/divisors/common.py create mode 100644 python/problems/functions/divisors/en.py create mode 100644 python/problems/functions/divisors/sl.py create mode 100644 python/problems/functions/divisors_sum/common.py create mode 100644 python/problems/functions/divisors_sum/en.py create mode 100644 python/problems/functions/divisors_sum/sl.py create mode 100644 python/problems/functions/friendly_numbers/common.py create mode 100644 python/problems/functions/friendly_numbers/en.py create mode 100644 python/problems/functions/friendly_numbers/sl.py create mode 100644 python/problems/functions/palindrome/common.py create mode 100644 python/problems/functions/palindrome/en.py create mode 100644 python/problems/functions/palindrome/sl.py create mode 100644 python/problems/functions/palindromic_numbers/common.py create mode 100644 python/problems/functions/palindromic_numbers/en.py create mode 100644 python/problems/functions/palindromic_numbers/sl.py create mode 100644 python/problems/functions/perfect_numbers/common.py create mode 100644 python/problems/functions/perfect_numbers/en.py create mode 100644 python/problems/functions/perfect_numbers/sl.py create mode 100644 python/problems/functions/prime_numbers/common.py create mode 100644 python/problems/functions/prime_numbers/en.py create mode 100644 python/problems/functions/prime_numbers/sl.py create mode 100644 python/problems/functions_and_modules/all/common.py create mode 100644 python/problems/functions_and_modules/all/en.py create mode 100644 python/problems/functions_and_modules/all/sl.py create mode 100644 python/problems/functions_and_modules/any/common.py create mode 100644 python/problems/functions_and_modules/any/en.py create mode 100644 python/problems/functions_and_modules/any/sl.py create mode 100644 python/problems/functions_and_modules/caesar_cipher/common.py create mode 100644 python/problems/functions_and_modules/caesar_cipher/en.py create mode 100644 python/problems/functions_and_modules/caesar_cipher/sl.py create mode 100644 python/problems/functions_and_modules/dominoes/common.py create mode 100644 python/problems/functions_and_modules/dominoes/en.py create mode 100644 python/problems/functions_and_modules/dominoes/sl.py create mode 100644 python/problems/functions_and_modules/en.py create mode 100644 python/problems/functions_and_modules/largest_sublist/common.py create mode 100644 python/problems/functions_and_modules/largest_sublist/en.py create mode 100644 python/problems/functions_and_modules/largest_sublist/sl.py create mode 100644 python/problems/functions_and_modules/lists_sum/common.py create mode 100644 python/problems/functions_and_modules/lists_sum/en.py create mode 100644 python/problems/functions_and_modules/lists_sum/sl.py create mode 100644 python/problems/functions_and_modules/longest_word/common.py create mode 100644 python/problems/functions_and_modules/longest_word/en.py create mode 100644 python/problems/functions_and_modules/longest_word/sl.py create mode 100644 python/problems/functions_and_modules/map/common.py create mode 100644 python/problems/functions_and_modules/map/en.py create mode 100644 python/problems/functions_and_modules/map/sl.py create mode 100644 python/problems/functions_and_modules/multiplicative_range/common.py create mode 100644 python/problems/functions_and_modules/multiplicative_range/en.py create mode 100644 python/problems/functions_and_modules/multiplicative_range/sl.py create mode 100644 python/problems/functions_and_modules/similarity/common.py create mode 100644 python/problems/functions_and_modules/similarity/en.py create mode 100644 python/problems/functions_and_modules/similarity/sl.py create mode 100644 python/problems/functions_and_modules/sl.py create mode 100644 python/problems/functions_and_modules/suspicious_words/common.py create mode 100644 python/problems/functions_and_modules/suspicious_words/en.py create mode 100644 python/problems/functions_and_modules/suspicious_words/sl.py 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 diff --git a/python/problems/functions/assign_numbers/common.py b/python/problems/functions/assign_numbers/common.py new file mode 100644 index 0000000..f00305a --- /dev/null +++ b/python/problems/functions/assign_numbers/common.py @@ -0,0 +1,47 @@ +# 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 = 225 +group = 'lists_and_for' +number = 4 +visible = True + +solution = '''\ +def numbers(xs): + ys = [] + for i in range(len(xs)): + ys.append((i, xs[i])) + return 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/functions/assign_numbers/en.py b/python/problems/functions/assign_numbers/en.py new file mode 100644 index 0000000..a68c6c8 --- /dev/null +++ b/python/problems/functions/assign_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 225 +name = 'Assign numbers' +slug = 'Assign numbers' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/assign_numbers/sl.py b/python/problems/functions/assign_numbers/sl.py new file mode 100644 index 0000000..97c0c3a --- /dev/null +++ b/python/problems/functions/assign_numbers/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 225 +name = 'Oštevilči' +slug = 'Oštevilči' + + +description = '''\ +

+Napišite funkcijo numbers(xs), ki vrne seznam oblike [(0, xs[0]), (1, xs[1]), ..., (n, xs[n])]. +Število n je enako dolžini seznama xs minus ena. +

+>>> numbers([4, 4, 4])
+[(0, 4), (1, 4), (2, 4)]
+>>> numbers([5, 1, 4, 2, 3])
+[(0, 5), (1, 1), (2, 4), (3, 2), (4, 3)]
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/body_mass_index/common.py b/python/problems/functions/body_mass_index/common.py new file mode 100644 index 0000000..fba7570 --- /dev/null +++ b/python/problems/functions/body_mass_index/common.py @@ -0,0 +1,47 @@ +# 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 = 226 +group = 'functions' +number = 5 +visible = True + +solution = '''\ +def bmi(xs): + ys = [] + for name, weight, height in xs: + ys.append((name, weight / (height / 100)**2)) + return 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/functions/body_mass_index/en.py b/python/problems/functions/body_mass_index/en.py new file mode 100644 index 0000000..fb4663f --- /dev/null +++ b/python/problems/functions/body_mass_index/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 226 +name = 'Body mass index' +slug = 'Body mass index' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/body_mass_index/sl.py b/python/problems/functions/body_mass_index/sl.py new file mode 100644 index 0000000..fd67c88 --- /dev/null +++ b/python/problems/functions/body_mass_index/sl.py @@ -0,0 +1,35 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 226 +name = 'Indeks telesne teže' +slug = 'Indeks telesne teže' + + +description = '''\ +

+Podan imamo seznam trojk: ime osebe, teža, višina, na primer: +

+>>> osebe = [('Ana', 55, 165), ('Berta', 60, 153)]
+
+Napišite funkcijo bmi(osebe), ki na podlagi podanega seznama osebe, sestavi seznam dvojk: ime osebe, indeks telesne teže: +
+>>> bmi(osebe)
+[('Ana', 20.202020202020204), ('Berta', 25.63116749967961)]
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/body_mass_index_2/common.py b/python/problems/functions/body_mass_index_2/common.py new file mode 100644 index 0000000..58c7ab1 --- /dev/null +++ b/python/problems/functions/body_mass_index_2/common.py @@ -0,0 +1,47 @@ +# 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 = 226 +group = 'functions' +number = 6 +visible = True + +solution = '''\ +def bmi2(names, weights, heights): + ys = [] + for name, weight, height in zip(names, weights, heights): + ys.append((name, weight / (height / 100)**2)) + return 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/functions/body_mass_index_2/en.py b/python/problems/functions/body_mass_index_2/en.py new file mode 100644 index 0000000..8ce2533 --- /dev/null +++ b/python/problems/functions/body_mass_index_2/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 226 +name = 'Body mass index 2' +slug = 'Body mass index 2' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/body_mass_index_2/sl.py b/python/problems/functions/body_mass_index_2/sl.py new file mode 100644 index 0000000..21e7fa0 --- /dev/null +++ b/python/problems/functions/body_mass_index_2/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 226 +name = 'Indeks telesne teže 2' +slug = 'Indeks telesne teže 2' + + +description = '''\ +

+Naloga je podobna prejšnji, le da imamo tokrat podatke v drugačni obliki: +

+>>> imena = ['Ana', 'Berta']
+>>> teze = [55, 60]
+>>> visine = [165, 153]
+>>> bmi2(imena, teze, visine)
+[('Ana', 20.202020202020204), ('Berta', 25.63116749967961)]
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/divisors/common.py b/python/problems/functions/divisors/common.py new file mode 100644 index 0000000..c3e71d8 --- /dev/null +++ b/python/problems/functions/divisors/common.py @@ -0,0 +1,46 @@ +# 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 = 230 +group = 'functions' +number = 9 +visible = True + +solution = '''\ +def divisors(n): + for i in range(1, n): + if n % i == 0: + print(i) +''' + +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/functions/divisors/en.py b/python/problems/functions/divisors/en.py new file mode 100644 index 0000000..d1e71c2 --- /dev/null +++ b/python/problems/functions/divisors/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 230 +name = 'Divisors' +slug = 'Divisors' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/divisors/sl.py b/python/problems/functions/divisors/sl.py new file mode 100644 index 0000000..76b0917 --- /dev/null +++ b/python/problems/functions/divisors/sl.py @@ -0,0 +1,26 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 230 +name = 'Delitelji' +slug = 'Delitelji' + + +description = '''\ +

+Napiši funkcijo divisors(n), ki izpiše vse delitelje števila (brez samega sebe), ki ga vnese uporabnik.

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/divisors_sum/common.py b/python/problems/functions/divisors_sum/common.py new file mode 100644 index 0000000..d6a2b88 --- /dev/null +++ b/python/problems/functions/divisors_sum/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 = 231 +group = 'functions' +number = 10 +visible = True + +solution = '''\ +def divisors_sum(n): + s = 0 + for i in range(1, n): + if n % i == 0: + s += i + return s +''' + +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/functions/divisors_sum/en.py b/python/problems/functions/divisors_sum/en.py new file mode 100644 index 0000000..67806f7 --- /dev/null +++ b/python/problems/functions/divisors_sum/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 231 +name = 'Divisors sum' +slug = 'Divisors sum' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/divisors_sum/sl.py b/python/problems/functions/divisors_sum/sl.py new file mode 100644 index 0000000..47b8719 --- /dev/null +++ b/python/problems/functions/divisors_sum/sl.py @@ -0,0 +1,27 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 231 +name = 'Vsota deliteljev' +slug = 'Vsota deliteljev' + + +description = '''\ +

+Napiši funkcijo divisors_sum(n), ki vrne vsoto vseh deliteljev števila, ki ga vnese uporabnik. +

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/friendly_numbers/common.py b/python/problems/functions/friendly_numbers/common.py new file mode 100644 index 0000000..415040e --- /dev/null +++ b/python/problems/functions/friendly_numbers/common.py @@ -0,0 +1,53 @@ +# 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 = 233 +group = 'functions' +number = 12 +visible = True + +solution = '''\ +def divisors_sum(n): + s = 0 + for i in range(1, n): + if n % i == 0: + s += i + return s + +def friendly_number(n): + s = divisors_sum(n) + if n == divisors_sum(s): + return s +''' + +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/functions/friendly_numbers/en.py b/python/problems/functions/friendly_numbers/en.py new file mode 100644 index 0000000..ba740ae --- /dev/null +++ b/python/problems/functions/friendly_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 233 +name = 'Friendly numbers' +slug = 'Friendly numbers' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/friendly_numbers/sl.py b/python/problems/functions/friendly_numbers/sl.py new file mode 100644 index 0000000..d1c15ff --- /dev/null +++ b/python/problems/functions/friendly_numbers/sl.py @@ -0,0 +1,37 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 233 +name = 'Prijateljska števila' +slug = 'Prijateljska števila' + + +description = '''\ +

+220 in 284 sta prijateljski števili. Delitelji 220 so 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 in 110. +Če jih seštejemo, dobimo 284. Delitelji 284 pa so 1, 2, 4, 71 in 142. Vsota teh števil pa je 220. +Napiši funkcijo friendly_number(n), ki vrne prijateljsko število številu n, če ga ima, oz. +vrne None, če ga nima. Primer: +

+>>> friendly_number(220)
+284
+>>> friendly_number(222)
+None
+
+

+

Uporabite funkcijo za vsoto deliteljev!

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/greatest_absolutist/sl.py b/python/problems/functions/greatest_absolutist/sl.py index d51cd96..ee33c6d 100644 --- a/python/problems/functions/greatest_absolutist/sl.py +++ b/python/problems/functions/greatest_absolutist/sl.py @@ -101,7 +101,7 @@ V tem primeru se lahko zgodi, da se zanka ne izteče do konca.

''', Tudi to nalogo lahko rešimo s funkcijo max:

 def max_abs(xs):
-    return max(xs, key = lambda x: abs(x))
+    return max(xs, key = abs(x))
 
''', } diff --git a/python/problems/functions/palindrome/common.py b/python/problems/functions/palindrome/common.py new file mode 100644 index 0000000..e012e8d --- /dev/null +++ b/python/problems/functions/palindrome/common.py @@ -0,0 +1,44 @@ +# 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 = 228 +group = 'functions' +number = 7 +visible = True + +solution = '''\ +def palindrome(s): + return s == s[::-1] +''' + +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/functions/palindrome/en.py b/python/problems/functions/palindrome/en.py new file mode 100644 index 0000000..784c395 --- /dev/null +++ b/python/problems/functions/palindrome/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 228 +name = 'Palindrome' +slug = 'Palindrome' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/palindrome/sl.py b/python/problems/functions/palindrome/sl.py new file mode 100644 index 0000000..e005057 --- /dev/null +++ b/python/problems/functions/palindrome/sl.py @@ -0,0 +1,33 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 228 +name = 'Palindrom' +slug = 'Palindrom' + + +description = '''\ +

+Napišite funkcijo palindrome(s), ki preveri, ali je niz s palindrom. +

+>>> palindrome('pericarezeracirep')
+True
+>>> palindrome('perica')
+False
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/palindromic_numbers/common.py b/python/problems/functions/palindromic_numbers/common.py new file mode 100644 index 0000000..ba518c7 --- /dev/null +++ b/python/problems/functions/palindromic_numbers/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 = 229 +group = 'functions' +number = 8 +visible = True + +solution = '''\ +def palindromic_numbers(): + xs = [] + for i in range(100, 1000): + for j in range(100, 1000): + if str(i * j) == str(i * j)[::-1]: + xs.append(i * j) + return max(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/functions/palindromic_numbers/en.py b/python/problems/functions/palindromic_numbers/en.py new file mode 100644 index 0000000..5f4ea76 --- /dev/null +++ b/python/problems/functions/palindromic_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 229 +name = 'Palindromic numbers' +slug = 'Palindromic numbers' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/palindromic_numbers/sl.py b/python/problems/functions/palindromic_numbers/sl.py new file mode 100644 index 0000000..8d64bab --- /dev/null +++ b/python/problems/functions/palindromic_numbers/sl.py @@ -0,0 +1,31 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 229 +name = 'Palindromska števila' +slug = 'Palindromska števila' + + +description = '''\ +

+Največje palindromsko število, ki ga lahko dobimo kot produkt dveh dvomestnih števil je 9009 = 91 * 99. +Napišite funkcijo palindromic_number(), ki poišče in vrne največje palindromsko število, +ki ga lahko dobimo kot produkt dveh tromestnih števil. + +Vir: Project Euler, Problem 4. +

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/perfect_numbers/common.py b/python/problems/functions/perfect_numbers/common.py new file mode 100644 index 0000000..ad1a7cd --- /dev/null +++ b/python/problems/functions/perfect_numbers/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 = 232 +group = 'functions' +number = 11 +visible = True + +solution = '''\ +def divisors_sum(n): + s = 0 + for i in range(1, n): + if n % i == 0: + s += i + return s + +def perfect(n): + return n == divisors_sum(n) +''' + +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/functions/perfect_numbers/en.py b/python/problems/functions/perfect_numbers/en.py new file mode 100644 index 0000000..a7cb94e --- /dev/null +++ b/python/problems/functions/perfect_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 232 +name = 'Perfect numbers' +slug = 'Perfect numbers' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/perfect_numbers/sl.py b/python/problems/functions/perfect_numbers/sl.py new file mode 100644 index 0000000..a354a17 --- /dev/null +++ b/python/problems/functions/perfect_numbers/sl.py @@ -0,0 +1,30 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 232 +name = 'Popolna števila' +slug = 'Popolna števila' + + +description = '''\ +

+Napiši funkcijo perfect(n), ki vrne True, če je podano število popolno, oz. False, č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. +

+

Uporabite funkcijo za vsoto deliteljev!

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions/prime_numbers/common.py b/python/problems/functions/prime_numbers/common.py new file mode 100644 index 0000000..0447c61 --- /dev/null +++ b/python/problems/functions/prime_numbers/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 = 234 +group = 'functions' +number = 13 +visible = True + +solution = '''\ +def prime(n): + for i in range(2, n): + for j in range(2, i): + if i % j == 0: + break + else: + print(i) +''' + +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/functions/prime_numbers/en.py b/python/problems/functions/prime_numbers/en.py new file mode 100644 index 0000000..87c01a2 --- /dev/null +++ b/python/problems/functions/prime_numbers/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 234 +name = 'Prime numbers' +slug = 'Prime numbers' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions/prime_numbers/sl.py b/python/problems/functions/prime_numbers/sl.py new file mode 100644 index 0000000..f6c6b24 --- /dev/null +++ b/python/problems/functions/prime_numbers/sl.py @@ -0,0 +1,27 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 234 +name = 'Praštevila' +slug = 'Praštevila' + + +description = '''\ +

+Napišite funkcijo prime(n), ki izpiše vsa praštevila manjša od n. +

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/all/common.py b/python/problems/functions_and_modules/all/common.py new file mode 100644 index 0000000..7fb60f5 --- /dev/null +++ b/python/problems/functions_and_modules/all/common.py @@ -0,0 +1,47 @@ +# 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 = 238 +group = 'functions_and_modules' +number = 4 +visible = True + +solution = '''\ +def all(xs): + for x in xs: + if not x: + return False + return True +''' + +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/functions_and_modules/all/en.py b/python/problems/functions_and_modules/all/en.py new file mode 100644 index 0000000..3028ad4 --- /dev/null +++ b/python/problems/functions_and_modules/all/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 238 +name = 'All' +slug = 'All' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/all/sl.py b/python/problems/functions_and_modules/all/sl.py new file mode 100644 index 0000000..f71fa4b --- /dev/null +++ b/python/problems/functions_and_modules/all/sl.py @@ -0,0 +1,40 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 238 +name = 'Vsi' +slug = 'Vsi' + + +description = '''\ +

+Napišite funkcijo all, ki sprejme seznam xs in vrne True, +če so vse vrednosti v seznamu resnične. Elementi seznama xs so lahko poljubnega tipa, ne le bool. +

+>>> all([True, True, False])
+False
+>>> all([True, True])
+True
+>>> all([1, 2, 3, 0])
+False
+>>> all(['foo', 42, True])
+True
+>>> all([])
+True
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/any/common.py b/python/problems/functions_and_modules/any/common.py new file mode 100644 index 0000000..78867c5 --- /dev/null +++ b/python/problems/functions_and_modules/any/common.py @@ -0,0 +1,47 @@ +# 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 = 239 +group = 'functions_and_modules' +number = 4 +visible = True + +solution = '''\ +def any(xs): + for x in xs: + if x: + return True + return False +''' + +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/functions_and_modules/any/en.py b/python/problems/functions_and_modules/any/en.py new file mode 100644 index 0000000..f5b94d9 --- /dev/null +++ b/python/problems/functions_and_modules/any/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 239 +name = 'Any' +slug = 'Any' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/any/sl.py b/python/problems/functions_and_modules/any/sl.py new file mode 100644 index 0000000..f32e50e --- /dev/null +++ b/python/problems/functions_and_modules/any/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 239 +name = 'Vsaj eden' +slug = 'Vsaj eden' + + +description = '''\ +

+Napišite funkcijo any(xs), ki deluje podobno kot all, le da vrne True, +če je vsaj ena vrednost v seznamu resnična. +

+>>> any([2, 3, 0])
+True
+>>> any([])
+False
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/caesar_cipher/common.py b/python/problems/functions_and_modules/caesar_cipher/common.py new file mode 100644 index 0000000..494a7f9 --- /dev/null +++ b/python/problems/functions_and_modules/caesar_cipher/common.py @@ -0,0 +1,52 @@ +# 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 = 243 +group = 'functions_and_modules' +number = 9 +visible = True + +solution = '''\ +def caesar(s): + cipher = '' + for c in s: + if 'a' <= c <= 'w': + cipher += chr(ord(c) + 3) + elif 'x' <= c <= 'z': + cipher += chr(ord(c) - 23) + else: + cipher += c + return cipher) +''' + +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/functions_and_modules/caesar_cipher/en.py b/python/problems/functions_and_modules/caesar_cipher/en.py new file mode 100644 index 0000000..bcfedee --- /dev/null +++ b/python/problems/functions_and_modules/caesar_cipher/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 243 +name = 'Caesar cipher' +slug = 'Caesar cipher' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/caesar_cipher/sl.py b/python/problems/functions_and_modules/caesar_cipher/sl.py new file mode 100644 index 0000000..ea4d9c8 --- /dev/null +++ b/python/problems/functions_and_modules/caesar_cipher/sl.py @@ -0,0 +1,35 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 243 +name = 'Cezarjeva šifra' +slug = 'Cezarjeva šifra' + + +description = '''\ +

+Napišite funkcijo caesar(s), ki podan niz zašifrira z uporabo cezarjeve šifre. +Preden se lotite naloge, se je morda vredno pozanimati kaj počneta funkciji +ord in +chr. +Predpostavite lahko, da niz s vsebuje le male črke angleške besede in presledke. +

+>>> caesar('the quick brown fox jumps over the lazy dog')
+'wkh txlfn eurzq ira mxpsv ryhu wkh odcb grj'
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/dominoes/common.py b/python/problems/functions_and_modules/dominoes/common.py new file mode 100644 index 0000000..5e73d8e --- /dev/null +++ b/python/problems/functions_and_modules/dominoes/common.py @@ -0,0 +1,47 @@ +# 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 = 240 +group = 'functions_and_modules' +number = 6 +visible = True + +solution = '''\ +def dominoes(domine): + for i in range(len(domine) - 1): + if domine[i][1] != domine[i + 1][0]: + return False + return True +''' + +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/functions_and_modules/dominoes/en.py b/python/problems/functions_and_modules/dominoes/en.py new file mode 100644 index 0000000..4d0d31b --- /dev/null +++ b/python/problems/functions_and_modules/dominoes/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 240 +name = 'Dominoes' +slug = 'Dominoes' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/dominoes/sl.py b/python/problems/functions_and_modules/dominoes/sl.py new file mode 100644 index 0000000..41cb860 --- /dev/null +++ b/python/problems/functions_and_modules/dominoes/sl.py @@ -0,0 +1,29 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 240 +name = 'Domine' +slug = 'Domine' + + +description = '''\ +

+Vrsta domin je podana s seznamom parov (terk), na primer +[(3, 6), (6, 6), (6, 1), (1, 0)] ali [(3, 6), (6, 6), (2, 3)]. Napišite funkcijo dominoes(xs), +ki prejme takšen seznam in pove, ali so domine pravilno zložene. Za prvi seznam mora vrniti True in za drugega False. +

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/en.py b/python/problems/functions_and_modules/en.py new file mode 100644 index 0000000..1218e73 --- /dev/null +++ b/python/problems/functions_and_modules/en.py @@ -0,0 +1,3 @@ +name = 'Functions and Modules' +description = 'Advanced functions and modules' + diff --git a/python/problems/functions_and_modules/largest_sublist/common.py b/python/problems/functions_and_modules/largest_sublist/common.py new file mode 100644 index 0000000..372e34f --- /dev/null +++ b/python/problems/functions_and_modules/largest_sublist/common.py @@ -0,0 +1,53 @@ +# 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 = 242 +group = 'functions_and_modules' +number = 8 +visible = True + +solution = '''\ +def largest_sublist(xss): + najvecji = [] + najvecji_vsota = float('-inf') + for xs in xss: + vsota = 0 + for x in xs: + vsota += x + if vsota > najvecji_vsota: + najvecji = xs + najvecji_vsota = vsota + return najvecji +''' + +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/functions_and_modules/largest_sublist/en.py b/python/problems/functions_and_modules/largest_sublist/en.py new file mode 100644 index 0000000..132eb39 --- /dev/null +++ b/python/problems/functions_and_modules/largest_sublist/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 242 +name = 'Largest sublist' +slug = 'Largest sublist' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/largest_sublist/sl.py b/python/problems/functions_and_modules/largest_sublist/sl.py new file mode 100644 index 0000000..b550ce2 --- /dev/null +++ b/python/problems/functions_and_modules/largest_sublist/sl.py @@ -0,0 +1,33 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 242 +name = 'Največji podseznam' +slug = 'Največji podseznam' + + +description = '''\ +

+Napiši funkcijo largest_sublist, ki vrne podseznam z največjo vsoto elementov. +

+>>> largest_sublist([[1, 1, 1], [1, 1]])
+[1, 1, 1]
+>>> largest_sublist([[2, 4, 1], [3, 1], [], [8, 2], [1, 1, 1, 1]])
+[8, 2]
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/lists_sum/common.py b/python/problems/functions_and_modules/lists_sum/common.py new file mode 100644 index 0000000..d3afef4 --- /dev/null +++ b/python/problems/functions_and_modules/lists_sum/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 = 241 +group = 'functions_and_modules' +number = 7 +visible = True + +solution = '''\ +def lists_sum(xss): + vsote = [] + for xs in xss: + vsota = 0 + for x in xs: + vsota += x + vsote.append(vsota) + return vsote +''' + +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/functions_and_modules/lists_sum/en.py b/python/problems/functions_and_modules/lists_sum/en.py new file mode 100644 index 0000000..12eaf0b --- /dev/null +++ b/python/problems/functions_and_modules/lists_sum/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 241 +name = 'Lists sum' +slug = 'Lists sum' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/lists_sum/sl.py b/python/problems/functions_and_modules/lists_sum/sl.py new file mode 100644 index 0000000..4baa002 --- /dev/null +++ b/python/problems/functions_and_modules/lists_sum/sl.py @@ -0,0 +1,35 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 241 +name = 'Vsota seznamov' +slug = 'Vsota seznamov' + + +description = '''\ +

+Podan je seznam seznamov, npr. [[2, 4, 1], [3, 1], [], [8, 2], [1, 1, 1, 1]]. +Napiši funkcijo lists_sum(xxs), ki v seznamu vrne vsote vseh elementov v posameznih podseznamih. +Za gornji seznam naj funkcija vrne seznam [7, 4, 0, 10, 4], saj je, na primer, 2 + 4 + 1 = 7. +

+>>> lists_sum([[1, 1, 1], [1, 1]])
+[3, 2]
+>>> lists_sum([[2, 4, 1], [3, 1], [], [8, 2], [1, 1, 1, 1]])
+[7, 4, 0, 10, 4]
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/longest_word/common.py b/python/problems/functions_and_modules/longest_word/common.py new file mode 100644 index 0000000..1201c1d --- /dev/null +++ b/python/problems/functions_and_modules/longest_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 = 235 +group = 'functions_and_modules' +number = 1 +visible = True + +solution = '''\ +def longest(s): + naj = '' + for beseda in s.split(): + if len(beseda) > len(naj): + naj = beseda + return naj +''' + +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/functions_and_modules/longest_word/en.py b/python/problems/functions_and_modules/longest_word/en.py new file mode 100644 index 0000000..7bd4dc2 --- /dev/null +++ b/python/problems/functions_and_modules/longest_word/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 235 +name = 'Longest word' +slug = 'Longest word' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/longest_word/sl.py b/python/problems/functions_and_modules/longest_word/sl.py new file mode 100644 index 0000000..eb85509 --- /dev/null +++ b/python/problems/functions_and_modules/longest_word/sl.py @@ -0,0 +1,30 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 235 +name = 'Najdaljša beseda' +slug = 'Najdaljša beseda' + + +description = '''\ +

+Napiši funkcijo longest(s), ki vrne najdaljšo besedo v nizu s. +

+>>> longest('an ban pet podgan')
+'podgan'
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/map/common.py b/python/problems/functions_and_modules/map/common.py new file mode 100644 index 0000000..e28f356 --- /dev/null +++ b/python/problems/functions_and_modules/map/common.py @@ -0,0 +1,47 @@ +# 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 = 245 +group = 'functions_and_modules' +number = 11 +visible = True + +solution = '''\ +def map(f, xs): + ys = [] + for x in xs: + ys.append(f(x)) + return 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/functions_and_modules/map/en.py b/python/problems/functions_and_modules/map/en.py new file mode 100644 index 0000000..dcc1785 --- /dev/null +++ b/python/problems/functions_and_modules/map/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 245 +name = 'Map' +slug = 'Map' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/map/sl.py b/python/problems/functions_and_modules/map/sl.py new file mode 100644 index 0000000..18c47fb --- /dev/null +++ b/python/problems/functions_and_modules/map/sl.py @@ -0,0 +1,34 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 245 +name = 'Slikaj' +slug = 'Slikaj' + + +description = '''\ +

+Napišite funkcijo map(f, xs), ki sprejme funkcijo f in seznam [x_1, x_2, ..., x_n] +in vrne nov seznam [f(x_1), f(x_2), ..., f(x_n)]. +

+>>> map(abs, [-5, 8, -3, -1, 3])
+[5, 8, 3, 1, 3]
+>>> map(len, "Daydream delusion limousine eyelash".split())
+[8, 8, 9, 7]
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/multiplicative_range/common.py b/python/problems/functions_and_modules/multiplicative_range/common.py new file mode 100644 index 0000000..9a52dce --- /dev/null +++ b/python/problems/functions_and_modules/multiplicative_range/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 = 244 +group = 'functions_and_modules' +number = 10 +visible = True + +solution = '''\ +def mrange(s, r, l): + xs = [] + for i in range(l): + xs.append(s) + s *= r + return 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/functions_and_modules/multiplicative_range/en.py b/python/problems/functions_and_modules/multiplicative_range/en.py new file mode 100644 index 0000000..566ef5f --- /dev/null +++ b/python/problems/functions_and_modules/multiplicative_range/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 244 +name = 'Multiplicative range' +slug = 'Multiplicative range' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/multiplicative_range/sl.py b/python/problems/functions_and_modules/multiplicative_range/sl.py new file mode 100644 index 0000000..8bd4bd0 --- /dev/null +++ b/python/problems/functions_and_modules/multiplicative_range/sl.py @@ -0,0 +1,32 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 244 +name = 'Multiplikativni range' +slug = 'Multiplikativni range' + + +description = '''\ +

+Napišite funkcijo mrange(start, factor, length), ki vrne seznam, kjer je vsako naslednje število za +factor večje od prejšnjega. Npr., v seznamu [1, 2, 4, 8, 16] je vsako naslednje število 2-krat večje od prejšnjega. +

+>>> print(mrange(7, 4, 7))
+[7, 28, 112, 448, 1792, 7168, 28672]
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/similarity/common.py b/python/problems/functions_and_modules/similarity/common.py new file mode 100644 index 0000000..5cb8fe7 --- /dev/null +++ b/python/problems/functions_and_modules/similarity/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 = 236 +group = 'functions_and_modules' +number = 2 +visible = True + +solution = '''\ +def similarity(s1, s2): + stevec = 0 + for i in range(min(len(s1), len(s2))): + if s1[i] == s2[i]: + stevec += 1 + return stevec +''' + +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/functions_and_modules/similarity/en.py b/python/problems/functions_and_modules/similarity/en.py new file mode 100644 index 0000000..e1dc014 --- /dev/null +++ b/python/problems/functions_and_modules/similarity/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 236 +name = 'Similarity' +slug = 'Similarity' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/similarity/sl.py b/python/problems/functions_and_modules/similarity/sl.py new file mode 100644 index 0000000..8aaf0b0 --- /dev/null +++ b/python/problems/functions_and_modules/similarity/sl.py @@ -0,0 +1,39 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 236 +name = 'Podobnost' +slug = 'Podobnost' + + +description = '''\ +

+Napišite funkcijo similarity(s1, s2), ki izračuna podobnost med dvema nizoma. +Podobnost definirajmo kot število mest v katerih se niza ujemata. +

+sobota
+robot
+------
+011110 -> 4
+
+>>> podobnost('sobota', 'robot')
+4
+>>> podobnost('robot', 'sobota')
+4
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} diff --git a/python/problems/functions_and_modules/sl.py b/python/problems/functions_and_modules/sl.py new file mode 100644 index 0000000..fb4f520 --- /dev/null +++ b/python/problems/functions_and_modules/sl.py @@ -0,0 +1,3 @@ +name = 'Funkcije in delo z moduli' +description = 'Uporaba funkcij in delo z moduli (predvsem z nizi)' + diff --git a/python/problems/functions_and_modules/suspicious_words/common.py b/python/problems/functions_and_modules/suspicious_words/common.py new file mode 100644 index 0000000..74868ab --- /dev/null +++ b/python/problems/functions_and_modules/suspicious_words/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 = 237 +group = 'functions_and_modules' +number = 3 +visible = True + +solution = '''\ +def suspicious(s): + susp = [] + for word in s.split(): + if 'u' in word and 'a' in word: + susp.append(word) + return susp +''' + +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/functions_and_modules/suspicious_words/en.py b/python/problems/functions_and_modules/suspicious_words/en.py new file mode 100644 index 0000000..9a406bf --- /dev/null +++ b/python/problems/functions_and_modules/suspicious_words/en.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +id = 237 +name = 'Suspicious words' +slug = 'Suspicious words' + +description = '''\ +

(translation missing)

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

(translation missing)

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

(translation missing)

''', +} diff --git a/python/problems/functions_and_modules/suspicious_words/sl.py b/python/problems/functions_and_modules/suspicious_words/sl.py new file mode 100644 index 0000000..3bf2c7b --- /dev/null +++ b/python/problems/functions_and_modules/suspicious_words/sl.py @@ -0,0 +1,32 @@ +# coding=utf-8 +import server +mod = server.problems.load_language('python', 'sl') + + +id = 237 +name = 'Sumljive besede' +slug = 'Sumljive besede' + + +description = '''\ +

+Napiši funkcijo suspicious(s), ki vrne seznam vseh sumljivih besed v danem nizu. +Beseda je sumljiva, če vsebuje tako črko u kot črko a. +

+>>> susupicious('Muha pa je rekla: "Tale juha se je pa res prilegla, najlepša huala," in odletela.')
+['Muha', 'juha', 'huala,"']
+
+

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

+''', + '''\ +

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

Program je pravilen!
+

+'''], +} 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 - * -: + +

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

+'''], +} diff --git a/python/problems/while_and_if/checking_account/en.py b/python/problems/while_and_if/checking_account/en.py index 1d36474..47633e8 100644 --- a/python/problems/while_and_if/checking_account/en.py +++ b/python/problems/while_and_if/checking_account/en.py @@ -1,8 +1,8 @@ # coding=utf-8 id = 199 -name = 'Checking Account' -slug = 'Checking Account' +name = 'Checking account' +slug = 'Checking account' description = '''\

(translation missing)

''' diff --git a/python/problems/while_and_if/consumers_anonymous/en.py b/python/problems/while_and_if/consumers_anonymous/en.py index 6331570..9691ac2 100644 --- a/python/problems/while_and_if/consumers_anonymous/en.py +++ b/python/problems/while_and_if/consumers_anonymous/en.py @@ -3,8 +3,8 @@ import server mod = server.problems.load_language('python', 'sl') id = 201 -name = 'Consumers Anonymous' -slug = 'Consumers Anonymous' +name = 'Consumers anonymous' +slug = 'Consumers anonymous' description = '''\

(translation missing)

''' -- cgit v1.2.1