diff options
author | Walther Neuper <neuper@neuper.(none)> | 2009-11-25 16:10:49 (GMT) |
---|---|---|
committer | Walther Neuper <neuper@neuper.(none)> | 2009-11-25 16:10:49 (GMT) |
commit | b33981b375a2e2e39705c942236ec9ae52c9fcf0 (patch) | |
tree | 778c391879200f5cc711f169be03096eed022202 | |
parent | cec1829a36b8c56940eee701a09ab3047aacfafe (diff) |
improved to_str_99;; added RP.tests/extimesdiv/test_
-rwxr-xr-x | ReckonPrimer.activity/extimesdiv.py | 4 | ||||
-rwxr-xr-x | ReckonPrimer.activity/functions.py | 23 | ||||
-rw-r--r-- | ReckonPrimer.tests/extimesdiv/test_generate_calc.py | 19 |
3 files changed, 15 insertions, 31 deletions
diff --git a/ReckonPrimer.activity/extimesdiv.py b/ReckonPrimer.activity/extimesdiv.py index e3887eb..acf42e9 100755 --- a/ReckonPrimer.activity/extimesdiv.py +++ b/ReckonPrimer.activity/extimesdiv.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# (c) Martin Neppel 2009 import gtk import pygtk @@ -391,8 +392,9 @@ class ExTimesDiv(Exercise): _calcs.append((_c, 5)) else: for _i in range(1,11): - #print('in Generate.tim_div, (j,i)=',(_j, _i)) + print('in Generate.tim_div, (j,i)=',(_j, _i)) if dic == '*': + #_c = [to_str_99(_i),'*',str(_j*10),'=',to_str_99(_i*_j*10)] _c = [to_str_99(_i),'*',str(_j),'=',to_str_99(_i*_j)] elif dic == '*commute': _c = [str(_j),'*',to_str_99(_i),'=',to_str_99(_i*_j)] diff --git a/ReckonPrimer.activity/functions.py b/ReckonPrimer.activity/functions.py index 8cc0c9e..0c8f646 100755 --- a/ReckonPrimer.activity/functions.py +++ b/ReckonPrimer.activity/functions.py @@ -1,4 +1,4 @@ -# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
"""the module for functions of reckonprimer.py.
placed in reconprimer.py caused recursive import."""
import copy
@@ -295,16 +295,17 @@ def strip(chars, c): #['1', '2', '3', '4']
def to_str_99(i):
- """convert a 2-digit number to a list of 2 characters;
- a leading 0 is displayed by #"""
- _10, _1 = divmod(i, 10)
- if _10 == 0:
- _10 = '#' #leading 0 can be removed by strip
- return [str(_10), str(_1)]
-#print(to_str_99(98))
-#['9', '8']
-#print(to_str_99(9))
-#['#', '9']
+ """ Convert a number to their list of digits (as characters). """
+ _digs = []
+ _lead, _dig = divmod(i, 10)
+ _digs.append(str(_dig))
+ while _lead > 9:
+ _lead, _dig = divmod(_lead, 10)
+ _digs.append(str(_dig))
+ if _lead > 0:
+ _digs.append(str(_lead))
+ _digs.reverse()
+ return _digs
def flatten(ls):
"""flatten a list of lists; only one level"""
diff --git a/ReckonPrimer.tests/extimesdiv/test_generate_calc.py b/ReckonPrimer.tests/extimesdiv/test_generate_calc.py deleted file mode 100644 index 5b83fc4..0000000 --- a/ReckonPrimer.tests/extimesdiv/test_generate_calc.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- - -print("==================================___________________=================") -print("===== ReckonPrimer.tests/timesdiv/test_generate_calc.py ==============") -print("-----") - -#WN091116 Exercise <10> does not generate calculations with "1+2 <" OFF -# Error Traceback ends with: -# File "/home/neuper/Activities/ReckonPrimer.activity/passten.py", line 53, in format -# return Exercise.format_addsub_simp((cs, linepos)) -# TypeError: unbound method format_addsub_simp() must be called with Exercise instance as first argument (got tuple instance instead) - -# _ex = ExTimesDiv(None) - - -print("===== ReckonPrimer.tests/timesdiv/test_generate_calc.py ==============") -print("========================= SUCCESS ~~~~~~~~~~~~~~~~~~==================") - - |