mathmaker
0.6(alpha)
|
00001 # -*- coding: utf-8 -*- 00002 00003 # Mathmaker creates automatically maths exercises sheets 00004 # with their answers 00005 # Copyright 2006-2014 Nicolas Hainaux <nico_h@users.sourceforge.net> 00006 00007 # This file is part of Mathmaker. 00008 00009 # Mathmaker is free software; you can redistribute it and/or modify 00010 # it under the terms of the GNU General Public License as published by 00011 # the Free Software Foundation; either version 3 of the License, or 00012 # any later version. 00013 00014 # Mathmaker is distributed in the hope that it will be useful, 00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 # GNU General Public License for more details. 00018 00019 # You should have received a copy of the GNU General Public License 00020 # along with Mathmaker; if not, write to the Free Software 00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 from lib import * 00024 from Q_Structure import Q_Structure 00025 00026 from core.base_calculus import * 00027 00028 00029 AVAILABLE_Q_KIND_VALUES = {'10m_2-9': ['default'], 00030 '10m_4-9': ['default'], 00031 '5m_3rm_2d_2-9': ['default'] 00032 } 00033 00034 # -------------------------------------------------------------------------- 00035 ## 00036 # @brief Produces a randomly list of ten products and results 00037 # @param embedded_machine The machine to be used 00038 # @param **options Any options 00039 # @return A couple ([products], [results]) 00040 def ten_products(pairs): 00041 00042 if not len(pairs) >= 10: 00043 raise error.WrongArgument("a list of at least 10 items", 00044 "a list containing less than 10 items") 00045 00046 calculus_list = [] 00047 results_list = [] 00048 00049 for i in range(10): 00050 current_pair = randomly.pop(pairs) 00051 if randomly.heads_or_tails(): 00052 calculus_list.append(Product([current_pair[0], 00053 current_pair[1]])) 00054 else: 00055 calculus_list.append(Product([current_pair[1], 00056 current_pair[0]])) 00057 00058 results_list.append(Product([current_pair[0], 00059 current_pair[1]]).evaluate() 00060 ) 00061 00062 return (calculus_list, results_list) 00063 00064 00065 00066 00067 00068 00069 # ------------------------------------------------------------------------------ 00070 # -------------------------------------------------------------------------- 00071 # ------------------------------------------------------------------------------ 00072 ## 00073 # @class Q_MentalCalculation 00074 # @brief Creates one whole tabular full of questions + answers 00075 class Q_MentalCalculation(Q_Structure): 00076 00077 00078 # -------------------------------------------------------------------------- 00079 ## 00080 # @brief Constructor. 00081 # @param embedded_machine The machine to be used 00082 # @param **options Any options 00083 # @return One instance of question.Q_MentalCalculation 00084 def __init__(self, embedded_machine, q_kind='default_nothing', **options): 00085 self.derived = True 00086 00087 # The call to the mother class __init__() method will set the 00088 # fields matching optional arguments which are so far : 00089 # self.q_kind, self.q_subkind 00090 # plus self.machine, self.options (modified) 00091 Q_Structure.__init__(self, embedded_machine, 00092 q_kind, AVAILABLE_Q_KIND_VALUES, 00093 **options) 00094 # The purpose of this next line is to get the possibly modified 00095 # value of **options 00096 options = self.options 00097 00098 self.calculus_list = [] 00099 self.results_list = [] 00100 00101 if q_kind == '10m_2-9': 00102 # The following intension list creates all (i , j) couples, i and 00103 # j taking their values in 2-9 and j >= i to avoid having duplicates 00104 # like (3, 2) which would be the same as (2, 3) 00105 # pairs = [(i, j) for i in xrange(2, 10) for j in xrange(i, 10)] 00106 # We put off 2×2 and 2×3 00107 pairs = [(2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), 00108 (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), 00109 (4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (4, 9), 00110 (5, 5), (5, 6), (5, 7), (5, 8), (5, 9), 00111 (6, 6), (6, 7), (6, 8), (6, 9), 00112 (7, 7), (7, 8), (7, 9), 00113 (8, 8), (8, 9), 00114 (9, 9)] 00115 00116 (self.calculus_list, self.results_list) = ten_products(pairs) 00117 00118 elif q_kind == '10m_4-9': 00119 # The following intension list creates all (i , j) couples, i and 00120 # j taking their values in 4-9 and j >= i to avoid having duplicates 00121 # like (5, 6) which would be the same as (6, 5) 00122 # pairs = [(i, j) for i in xrange(4, 10) for j in xrange(i, 10)] 00123 pairs = [(4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (4, 9), 00124 (5, 5), (5, 6), (5, 7), (5, 8), (5, 9), (6, 6), 00125 (6, 7), (6, 8), (6, 9), (7, 7), (7, 8), (7, 9), 00126 (8, 8), (8, 9), (9, 9)] 00127 00128 00129 (self.calculus_list, self.results_list) = ten_products(pairs) 00130 00131 00132 elif q_kind == '5m_3rm_2d_2-9': 00133 # The following intension list creates all (i , j) couples, i and 00134 # j take their values in 2 - 9 and j >= i to avoid having duplicates 00135 # like (3, 2) which would be the same as (2, 3) 00136 # pairs = [(i, j) for i in xrange(2, 10) for j in xrange(i, 10)] 00137 # We put off 2×2 and 2×3 00138 pairs = [(2, 4), (2, 5), (2, 6), (2, 7), (2, 8), (2, 9), 00139 (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), 00140 (4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (4, 9), 00141 (5, 5), (5, 6), (5, 7), (5, 8), (5, 9), 00142 (6, 6), (6, 7), (6, 8), (6, 9), 00143 (7, 7), (7, 8), (7, 9), 00144 (8, 8), (8, 9), 00145 (9, 9)] 00146 00147 for i in range(5): 00148 current_pair = randomly.pop(pairs) 00149 if randomly.heads_or_tails(): 00150 self.calculus_list.append(Product([current_pair[0], 00151 current_pair[1]])) 00152 else: 00153 self.calculus_list.append(Product([current_pair[1], 00154 current_pair[0]])) 00155 00156 self.results_list.append(Product([current_pair[0], 00157 current_pair[1]]).evaluate() 00158 ) 00159 00160 for i in range(3): 00161 current_pair = randomly.pop(pairs) 00162 self.calculus_list.append(Product([current_pair[0], 00163 current_pair[1]]).evaluate() 00164 ) 00165 00166 self.results_list.append(Product([current_pair[0], 00167 current_pair[1]])) 00168 00169 # We put (2, 2) and (2, 3) back in the possible pairs 00170 pairs.append((2, 2)) 00171 pairs.append((2, 3)) 00172 00173 for i in range(2): 00174 current_pair = randomly.pop(pairs) 00175 00176 if randomly.heads_or_tails(): 00177 quotient = Quotient(('+', 00178 Product([current_pair[0], 00179 current_pair[1]]).evaluate(), 00180 current_pair[0]), 00181 use_divide_symbol='yes') 00182 00183 self.calculus_list.append(quotient) 00184 00185 self.results_list.append(current_pair[1]) 00186 00187 else: 00188 quotient = Quotient(('+', 00189 Product([current_pair[0], 00190 current_pair[1]]).evaluate(), 00191 current_pair[1]), 00192 use_divide_symbol='yes') 00193 00194 self.calculus_list.append(quotient) 00195 00196 self.results_list.append(current_pair[0]) 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 # -------------------------------------------------------------------------- 00207 ## 00208 # @brief Returns the text of the question as a str 00209 def text_to_str(self): 00210 M = self.machine 00211 00212 result = M.write(_("Date") + " : ............." \ 00213 + _("Class") + " : .............") 00214 00215 result += M.write_new_line() 00216 00217 size = (3, 10) 00218 col_widths = [1.4 for i in range(10)] 00219 content = [i+1 for i in range(10)] \ 00220 + [M.write_math_style2(\ 00221 M.type_string(self.calculus_list[i])) for i in range(10)] \ 00222 + [M.write_math_style2(\ 00223 M.type_string(self.results_list[i])) for i in range(10)] 00224 00225 result += M.write_layout(size, col_widths, content, 00226 borders='all', center='ok') 00227 00228 result += M.write_new_line_twice() 00229 00230 return result 00231 00232 00233 00234 00235 00236 00237 00238 00239 # -------------------------------------------------------------------------- 00240 ## 00241 # @brief Returns the answer of the question as a str 00242 def answer_to_str(self): 00243 pass 00244 00245 00246 00247 00248