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

Program deluje pravilno!
Namig za bolj učinkovit program: ni vedno potrebno, da se program pregleda vse elemente. Če najdemo vrednost 42, nam ni potrebno več naprej iskati - zanko lahko prekinemo z ukazom break

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

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

+'''], } diff --git a/python/problems/lists_and_for/contains_string/common.py b/python/problems/lists_and_for/contains_string/common.py index 29bc9f2..1f19d7f 100644 --- a/python/problems/lists_and_for/contains_string/common.py +++ b/python/problems/lists_and_for/contains_string/common.py @@ -25,7 +25,8 @@ hint_type = { 'for_loop': Hint('for_loop'), 'if_clause': Hint('if_clause'), 'printing': Hint('printing'), - 'print_out_for': Hint('print_out_for') + 'print_out_for': Hint('print_out_for'), + 'final_hint': Hint('final_hint') } def test(python, code): @@ -36,12 +37,12 @@ def test(python, code): [], ['Waldo']] test_out = [ + False, True, True, True, False, - True, - False + True ] n_correct = 0 @@ -69,6 +70,9 @@ def test(python, code): hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_xs)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + if passed: + hints.append({'id': 'final_hint'}) + return passed, hints def hint(python, code): diff --git a/python/problems/lists_and_for/contains_string/sl.py b/python/problems/lists_and_for/contains_string/sl.py index d177463..49f0ed0 100644 --- a/python/problems/lists_and_for/contains_string/sl.py +++ b/python/problems/lists_and_for/contains_string/sl.py @@ -20,7 +20,7 @@ xs = ['foo', 'bar', 'baz', 'Waldo', 'foobar'] for_loop = ['''\

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

Najlažje bo s for zanko. +

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

Poskusii naslednji dve vrstici:

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

Plan je enak kot pri prvi nalogi: +

Plan je enak kot pri prvi nalogi:

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

Izpiši rezultat!

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

Pazi, da izpišeš rezultat izven zanke!

'''] +

Pazi, da izpišeš rezultat izven zanke!

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

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

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

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

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

Pazi, da izpišeš rezultat izven zanke!

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

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

+ 'final_hint': ['''\ +

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

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

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

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

Število deli samega sebe!

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

Naloga rešena!

-

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

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

-from math import sqrt
+from math import *
+
 n = int(input('Vnesi število: '))
-for i in range(1, sqrt(n)+1):
+for i in range(1, int(sqrt(n)+1)):
     if n % i == 0:
         print(i, n/i)
 
'''], -- cgit v1.2.1