From 1f9f6de923e4b490c42a44d660b3e32dbe11426e Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 8 Oct 2015 11:17:16 +0200 Subject: Added final hint to contains_42. --- .../introduction/fahrenheit_to_celsius/common.py | 4 ++++ .../introduction/fahrenheit_to_celsius/sl.py | 2 +- python/problems/lists_and_for/contains_42/common.py | 14 +++++++++++++- python/problems/lists_and_for/contains_42/sl.py | 21 +++++++++++++++------ 4 files changed, 33 insertions(+), 8 deletions(-) (limited to 'python/problems') diff --git a/python/problems/introduction/fahrenheit_to_celsius/common.py b/python/problems/introduction/fahrenheit_to_celsius/common.py index 6549c32..918c643 100644 --- a/python/problems/introduction/fahrenheit_to_celsius/common.py +++ b/python/problems/introduction/fahrenheit_to_celsius/common.py @@ -3,6 +3,7 @@ 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 +import re id = 180 group = 'introduction' @@ -87,6 +88,9 @@ def hint(python, code): if not has_token_sequence(tokens, ['input']): return [{'id': 'no_input_call'}] + if not re.findall(r'=[^\n]*?input', code): + return [{'id': 'no_input_call'}] + # if tokens * or / or = are not in code, we have to teach them how to # evaluate expressions. if (not has_token_sequence(tokens, ['/']) or diff --git a/python/problems/introduction/fahrenheit_to_celsius/sl.py b/python/problems/introduction/fahrenheit_to_celsius/sl.py index b61c436..ae3db5f 100644 --- a/python/problems/introduction/fahrenheit_to_celsius/sl.py +++ b/python/problems/introduction/fahrenheit_to_celsius/sl.py @@ -12,7 +12,7 @@ stopinjah, program pa jo izpiše v Celzijevih. Med temperaturama pretvarjamo po formuli C = 5/9 (F – 32).

''' no_input_call = ['''\ -

Uporabnika nekaj vprašamo s funkcijo input.

''', +

Uporabi funkcijo input in shrani rezultat.

''', '''\

Funkcija input sprejme niz (angl. string), ki se prikaže uporabniku kot vprašanje in vrača, kar je uporabnik napisal.

''', diff --git a/python/problems/lists_and_for/contains_42/common.py b/python/problems/lists_and_for/contains_42/common.py index f91465f..d4c4af8 100644 --- a/python/problems/lists_and_for/contains_42/common.py +++ b/python/problems/lists_and_for/contains_42/common.py @@ -25,10 +25,15 @@ hint_type = { 'for_loop': Hint('for_loop'), 'if_clause': Hint('if_clause'), 'printing': Hint('printing'), - 'print_out_for': Hint('print_out_for') + 'print_out_for': Hint('print_out_for'), + 'seen_42': Hint('seen_42'), + 'final_hint': Hint('final_hint'), + 'final_hint_nobreak': Hint('final_hint_nobreak') } def test(python, code): + tokens = get_tokens(code) + test_xs = [[42, 5, 4, -7, 2, 12, -3, -4, 11, 42, 2], [42, 5, 4, -7, 2, 12, -3, -4, 11, 2], [5, 4, -7, 2, 12, -3, -4, 11, 2], @@ -71,6 +76,11 @@ def test(python, code): hints = [{'id': 'test_results', 'args': {'passed': n_correct, 'total': len(test_xs)}}] if tin: hints.append({'id': 'problematic_test_case', 'args': {'testin': str(tin), 'testout': str(tout)}}) + else: + if has_token_sequence(tokens, ['break']): + hints.append({'id' : 'final_hint'}) + else: + hints.append({'id' : 'final_hint_nobreak'}) return passed, hints def hint(python, code): @@ -101,5 +111,7 @@ def hint(python, code): if not has_token_sequence(tokens, ['\n', 'print']): return [{'id' : 'print_out_for'}] + if not has_token_sequence(tokens, ['=', 'True']): + return [{'id' : 'seen_42'}] return None diff --git a/python/problems/lists_and_for/contains_42/sl.py b/python/problems/lists_and_for/contains_42/sl.py index fe6b57e..1a40549 100644 --- a/python/problems/lists_and_for/contains_42/sl.py +++ b/python/problems/lists_and_for/contains_42/sl.py @@ -21,10 +21,10 @@ Seveda mora program delati za poljubne sezname in ne samo za seznam iz primera.< for_loop = ['''\

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

Najlažje bo s for zanko. +

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

Poskusii naslednji dve vrstici:

+

Poskusi naslednji dve vrstici:

 for x in xs:
     print (x)
@@ -36,9 +36,9 @@ Kaj naj Python naredi s to spremenljivko, je zapisano v zamaknjenih vrsticah.
 Tokrat vrednost le izpišemo.

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

Preveri, ali imamo število 42?

''', +

Preveri, ali imamo število 42?

''', '''\ -

Uporabi pogojni stavek if!

''', +

Uporabi pogojni stavek if!

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

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

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

+

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

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

Izpiši rezultat.

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

Pazi, da izpišeš rezultat izven zanke!

'''] +

Pazi, da izpišeš rezultat izven zanke!

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

Program deluje pravilno!

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

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

'''], } -- cgit v1.2.1