From 5db9e65c81bdf81ed4030040ff3666362e860d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mo=C5=BEina?= Date: Thu, 29 Oct 2015 16:08:34 +0100 Subject: Bugfix. Added some hints. --- .../problems/functions/body_mass_index/common.py | 17 ++++++++++-- .../problems/functions/body_mass_index_2/common.py | 17 ++++++++++-- python/problems/functions/greatest/sl.py | 6 ++-- .../problems/functions/greatest_absolutist/sl.py | 6 ++-- python/problems/functions/greatest_negative/sl.py | 4 +-- .../functions_and_modules/longest_word/sl.py | 32 +++++++++++++++++++--- 6 files changed, 64 insertions(+), 18 deletions(-) (limited to 'python') diff --git a/python/problems/functions/body_mass_index/common.py b/python/problems/functions/body_mass_index/common.py index 8e774be..1ff56b6 100644 --- a/python/problems/functions/body_mass_index/common.py +++ b/python/problems/functions/body_mass_index/common.py @@ -2,7 +2,7 @@ import re from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc + string_contains_number, get_tokens, get_numbers, get_exception_desc, almost_equal from server.hints import Hint id = 226 @@ -42,8 +42,19 @@ def test(python, code): n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): - n_correct += ans[0] == to - if ans[0] != to: + corr = 0 + if isinstance(ans[0], list) and len(ans[0]) == len(to): + corr = 1 + for v1, v2 in zip(ans[0], to): + if not isinstance(v1, tuple) or len(v1) != len(v2): + corr = 0 + break + if v1[0] != v2[0] or not almost_equal(v1[1], v2[1], 2): + corr = 0 + break + + n_correct += corr + if not corr: tin = test_in[i][0] tout = to diff --git a/python/problems/functions/body_mass_index_2/common.py b/python/problems/functions/body_mass_index_2/common.py index c6cf2b3..176a59d 100644 --- a/python/problems/functions/body_mass_index_2/common.py +++ b/python/problems/functions/body_mass_index_2/common.py @@ -2,7 +2,7 @@ import re from python.util import has_token_sequence, string_almost_equal, \ - string_contains_number, get_tokens, get_numbers, get_exception_desc + string_contains_number, get_tokens, get_numbers, get_exception_desc, almost_equal from server.hints import Hint id = 227 @@ -42,8 +42,19 @@ def test(python, code): n_correct = 0 tin, tout = None, None for i, (ans, to) in enumerate(zip(answers, test_out)): - n_correct += ans[0] == to - if ans[0] != to: + corr = 0 + if isinstance(ans[0], list) and len(ans[0]) == len(to): + corr = 1 + for v1, v2 in zip(ans[0], to): + if not isinstance(v1, tuple) or len(v1) != len(v2): + corr = 0 + break + if v1[0] != v2[0] or not almost_equal(v1[1], v2[1], 2): + corr = 0 + break + + n_correct += corr + if not corr: tin = test_in[i][0] tout = to diff --git a/python/problems/functions/greatest/sl.py b/python/problems/functions/greatest/sl.py index a32aada..467de07 100644 --- a/python/problems/functions/greatest/sl.py +++ b/python/problems/functions/greatest/sl.py @@ -27,7 +27,7 @@ def max_val(xs): '''] main_plan = ['''\ -

Ideja: po vrsti pogledamo vse elemente in sproti hranimo največjega.

''', +

Ideja: po vrsti pogledamo vse elemente in sproti hranimo največjega.

''', '''\
  1. Začnemo s prvim elementom in si ga zapomnimo kot največjega.
  2. @@ -51,7 +51,7 @@ return_clause = ['''\

    Namesto, da izpišemo rezultat, ga vračamo s stavkom return.

    '''] plan = [['''\ -

    Najprej poskusi napisati program (brez funkcije), ki v xs poišče največji element

    ''', +

    Najprej poskusi napisati program (brez funkcije), ki v xs poišče največji element

    ''', '''\
     xs = [5, 1, -6, -7, 2]
    @@ -106,7 +106,7 @@ hint = {
         'if_clause': if_clause,
     
         'final_hint': '''\
    -

    Odlično, naloga rešena! Še zanimivost: Python ima funkcijo max že vgrajeno:

    +

    Odlično, naloga rešena! Še zanimivost: Python ima funkcijo max že vgrajeno:

     def max_val(xs):
         return max(xs)
    diff --git a/python/problems/functions/greatest_absolutist/sl.py b/python/problems/functions/greatest_absolutist/sl.py
    index 79cfb06..dd0bd99 100644
    --- a/python/problems/functions/greatest_absolutist/sl.py
    +++ b/python/problems/functions/greatest_absolutist/sl.py
    @@ -17,7 +17,7 @@ absolutni vrednosti v seznamu xs.

    ''' function = ['''\ -

    Napiši definicijo funkcije max_abs(xs).

    ''', +

    Napiši definicijo funkcije max_abs(xs).

    ''', '''\

    Definicijo funkcije začnemo z def, temu sledi ime, potem oklepaji, v katerih naštejemo argumente funkcije, nato zaklepaj in na koncu dvopičje

    ''', @@ -31,7 +31,7 @@ print (max_abs(s))
    '''] main_plan = ['''\ -

    Plan: po vrsti pogledamo vse elemente in sproti hranimo največjega +

    Plan: po vrsti pogledamo vse elemente in sproti hranimo največjega (glede na absolutno vrednost).

    ''', '''\
    @@ -96,7 +96,7 @@ hint = {
     V tem primeru se lahko zgodi, da se zanka ne izteče do konca.

    ''', 'final_hint': '''\ -

    Odlično, naloga rešena! Še zanimivost: +

    Odlično, naloga rešena! Še zanimivost: Tudi to nalogo lahko rešimo s funkcijo max:

     def max_abs(xs):
    diff --git a/python/problems/functions/greatest_negative/sl.py b/python/problems/functions/greatest_negative/sl.py
    index 31f1fd6..38a9f08 100644
    --- a/python/problems/functions/greatest_negative/sl.py
    +++ b/python/problems/functions/greatest_negative/sl.py
    @@ -17,7 +17,7 @@ v seznamu xs. Če seznam nima negativnih števil, naj funkcija vrne
     '''
     
     function = ['''\
    -

    Napiši definicijo funkcije max_neg(xs).

    ''', +

    Napiši definicijo funkcije max_neg(xs).

    ''', '''\

    Definicijo funkcije začnemo z def, temu sledi ime, potem oklepaji, v katerih naštejemo argumente funkcije, nato zaklepaj in na koncu dvopičje

    ''', @@ -31,7 +31,7 @@ print (max_neg(s))
    '''] main_plan = ['''\ -

    Plan: po vrsti pogledamo vse elemente in sproti hranimo največje negativno +

    Plan: po vrsti pogledamo vse elemente in sproti hranimo največje negativno število.

    ''', '''\

    Na začetku ne moremo največjemu nastaviti vrednosti prvega elementa v seznamu, diff --git a/python/problems/functions_and_modules/longest_word/sl.py b/python/problems/functions_and_modules/longest_word/sl.py index eb85509..0d4b057 100644 --- a/python/problems/functions_and_modules/longest_word/sl.py +++ b/python/problems/functions_and_modules/longest_word/sl.py @@ -16,11 +16,35 @@ Napiši funkcijo longest(s), ki vrne najdaljšo besedo v nizu ''' -plan = ['''\ -

    -''', +split = ['''\ +

    +Uporabi metodo split, ki razdeli niz na podnize.

    ''', + '''\ +
    +>>> st = 'an ban pet podgan'
    +>>> st.split()
    +['an', 'ban', 'pet, 'podgan']
    +
    +'''] + +len_func = [ '''\ -

    '''] +

    Funkcija len vrne dolžino niza (pa tudi seznama, terke, itd.)

    '''] + + + + +plan = [split, +'''\ +
    +def longest(s):
    +    z zanko čez vse besede
    +        če je beseda daljša od trenutno najdaljše besede
    +            ustrezno spremeni najdaljšo besedo
    +    vrni rezultat
    +
    +''', + len_func] hint = { 'final_hint': ['''\ -- cgit v1.2.1