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 X_Structure import X_Structure 00025 import question 00026 00027 AVAILABLE_X_KIND_VALUES = \ 00028 {'short_test' : ['easy', 'medium_level'], 00029 'preformatted' : ['product'], 00030 'bypass' : ['sum', 'sum_of_products'] 00031 } 00032 00033 X_LAYOUT_UNIT = "cm" 00034 # ---------------------- lines_nb col_widths questions 00035 X_LAYOUTS = {'default' : 00036 { 'exc' : [ None, 'all' 00037 ], 00038 'ans' : [ None, 'all' 00039 ] 00040 } 00041 } 00042 00043 # ------------------------------------------------------------------------------ 00044 # -------------------------------------------------------------------------- 00045 # ------------------------------------------------------------------------------ 00046 ## 00047 # @class X_AlgebraExpressionReduction 00048 # @brief This new exercise object should include all possible 00049 # reduction exercises 00050 class X_AlgebraExpressionReduction(X_Structure): 00051 00052 00053 00054 00055 00056 # -------------------------------------------------------------------------- 00057 ## 00058 # @brief Constructor. 00059 # @param embedded_machine The machine that will be used to write output. 00060 # @param **options Options detailed below : 00061 # - start_number=<integer> 00062 # (should be >= 1) 00063 # - number_of_questions=<integer> 00064 # /!\ only useful if you use x_kind and not preformatted 00065 # (should be >= 1) 00066 # - x_kind=<string> 00067 # ... 00068 # ... 00069 # - preformatted=<string> 00070 # /!\ preformatted is useless with short_test 00071 # /!\ number_of_questions is useless with preformatted 00072 # /!\ if you use it with the x_kind option, ensure there's a 00073 # preformatted possibility with this option 00074 # 'yes' 00075 # 'OK' 00076 # any other value will be understood as 'no' 00077 # - short_test=<string> 00078 # /!\ the x_kind option above can't be used along this option 00079 # 'yes' 00080 # 'OK' 00081 # any other value will be understood as 'no' 00082 # @return One instance of exercise.ExpressionReduction 00083 def __init__(self, embedded_machine, x_kind = 'default_nothing', **options): 00084 self.derived = True 00085 X_Structure.__init__(self, embedded_machine, 00086 x_kind, AVAILABLE_X_KIND_VALUES, X_LAYOUTS, 00087 X_LAYOUT_UNIT, **options) 00088 # The purpose of this next line is to get the possibly modified 00089 # value of **options 00090 options = self.options 00091 00092 default_question = question.Q_AlgebraExpressionReduction 00093 00094 # TEXTS OF THE EXERCISES 00095 self.text = {'exc' : _("Reduce the following expressions :"), 00096 'ans' : "" 00097 } 00098 00099 # alternate texts section 00100 if self.x_subkind == 'product': 00101 self.text = {'exc' : \ 00102 _("Reduce, if possible, the following products :"), 00103 'ans' : \ 00104 _("Pay attention that the intermediate line is optional.") 00105 } 00106 00107 #elif self.x_subkind == 'sum_of_products': 00108 # self.text = _("Reduce the following expressions :") 00109 00110 elif self.x_subkind == 'sum': 00111 self.text = {'exc' : \ 00112 _("Reduce, if possible, the following sums :"), 00113 'ans' : \ 00114 _("Pay attention that the intermediate line is optional.") 00115 } 00116 00117 # SHORT TEST EXERCISES 00118 if self.x_kind == 'short_test': 00119 if self.x_subkind == 'easy': 00120 self.questions_list.append(default_question(self.machine, 00121 q_kind='product', 00122 short_test='OK', 00123 expression_number=0) 00124 ) 00125 00126 self.questions_list.append(default_question(self.machine, 00127 q_kind='sum', 00128 short_test='OK', 00129 length=4, 00130 expression_number=1) 00131 ) 00132 00133 self.questions_list.append(default_question(self.machine, 00134 q_kind='sum_of_products', 00135 length=2, 00136 expression_number=2) 00137 ) 00138 00139 if self.x_subkind == 'medium_level': 00140 q = [] 00141 00142 q.append(default_question(self.machine, 00143 q_kind='long_sum', 00144 expression_number=2) 00145 ) 00146 00147 q.append(default_question(self.machine, 00148 q_kind='sum_not_reducible', 00149 expression_number=3) 00150 ) 00151 00152 q.append(default_question(self.machine, 00153 q_kind='sum_with_minus-brackets', 00154 minus_brackets_nb=2, 00155 plus_brackets_nb=1, 00156 expression_number=4) 00157 ) 00158 00159 q.append(default_question(self.machine, 00160 q_kind='long_sum_including_a_coeff_1', 00161 length=7, 00162 expression_number=5) 00163 ) 00164 00165 for i in range(len(q)): 00166 self.questions_list.append(randomly.pop(q)) 00167 00168 # PREFORMATTED EXERCISES 00169 elif self.x_kind == 'preformatted': 00170 if self.x_subkind == 'product': 00171 self.questions_list.append(default_question( 00172 self.machine, 00173 q_kind='product', 00174 expression_number=0, 00175 use_these_letters=['a', 'b'], 00176 nb_occurences_of_the_same_letter=1, 00177 **options 00178 )) 00179 00180 self.questions_list.append(default_question(\ 00181 self.machine, 00182 q_kind='product', 00183 expression_number=1, 00184 use_these_letters=['x', 'y'], 00185 nb_occurences_of_the_same_letter=1, 00186 **options 00187 )) 00188 00189 self.questions_list.append(default_question( 00190 self.machine, 00191 q_kind='product', 00192 expression_number=2, 00193 use_these_letters=['t', 'u'], 00194 nb_occurences_of_the_same_letter=1, 00195 **options 00196 )) 00197 00198 self.questions_list.append(default_question( 00199 self.machine, 00200 q_kind='product', 00201 expression_number=3, 00202 use_these_letters=['x', 'y', 'z'], 00203 nb_occurences_of_the_same_letter=1, 00204 **options 00205 )) 00206 00207 self.questions_list.append(default_question( 00208 self.machine, 00209 q_kind='product', 00210 expression_number=4, 00211 use_these_letters=['p', 'q', 'r'], 00212 **options 00213 )) 00214 00215 self.questions_list.append(default_question( 00216 self.machine, 00217 q_kind='product', 00218 expression_number=5, 00219 use_these_letters=['a', 'b', 'x'], 00220 nb_occurences_of_the_same_letter=1, 00221 **options 00222 )) 00223 00224 self.questions_list.append(default_question( 00225 self.machine, 00226 q_kind='product', 00227 expression_number=6, 00228 use_reduced_alphabet='OK', 00229 nb_occurences_of_the_same_letter=1, 00230 **options 00231 )) 00232 00233 self.questions_list.append(default_question( 00234 self.machine, 00235 q_kind='product', 00236 expression_number=7, 00237 use_these_letters=['a', 'b', 'x'], 00238 nb_occurences_of_the_same_letter=1, 00239 **options 00240 )) 00241 00242 self.questions_list.append(default_question( 00243 self.machine, 00244 q_kind='product', 00245 expression_number=8, 00246 use_these_letters=['x', 'y'], 00247 nb_occurences_of_the_same_letter=1, 00248 **options 00249 )) 00250 00251 00252 # OTHER EXERCISES (BYPASS OPTION) 00253 else: 00254 for i in range(self.q_nb): 00255 self.questions_list.append( \ 00256 default_question(self.machine, 00257 q_kind=self.x_subkind, 00258 expression_number=i+self.start_number, 00259 **options) 00260 ) 00261 00262 00263 00264 00265 00266