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 from core.base_calculus import * 00026 from core.calculus import * 00027 from lib.common.cst import * 00028 00029 AVAILABLE_Q_KIND_VALUES = {'any_basic': ['default'], 00030 'basic_addition': ['default'], 00031 'basic_addition_r': ['default'], 00032 'any_basic_addition': ['default'], 00033 'basic_multiplication': ['default'], 00034 'basic_multiplication_r': ['default'], 00035 'any_basic_multiplication': ['default'], 00036 'any_classic': ['default'], 00037 'classic': ['default'], 00038 'classic_r': ['default'], 00039 'classic_with_fractions': ['default'], 00040 'classic_x_twice': ['default'], 00041 'any_simple_expandable': ['default'], 00042 'any_double_expandable': ['default'] 00043 } 00044 00045 00046 00047 00048 00049 # ------------------------------------------------------------------------------ 00050 # -------------------------------------------------------------------------- 00051 # ------------------------------------------------------------------------------ 00052 ## 00053 # @class Q_Equation 00054 # @brief All questions about Equations (first degree, one unknown variable) 00055 class Q_Equation(Q_Structure): 00056 00057 00058 00059 00060 00061 # -------------------------------------------------------------------------- 00062 ## 00063 # @brief Constructor. 00064 # @param embedded_machine The machine to be used 00065 # @param **options Any options 00066 # @return One instance of question.Q_Equation 00067 def __init__(self, embedded_machine, q_kind='default_nothing', **options): 00068 self.derived = True 00069 00070 # The call to the mother class __init__() method will set the 00071 # fields matching optional arguments which are so far : 00072 # self.q_kind, self.q_subkind 00073 # plus self.machine, self.options (modified) 00074 Q_Structure.__init__(self, embedded_machine, 00075 q_kind, AVAILABLE_Q_KIND_VALUES, 00076 **options) 00077 # The purpose of this next line is to get the possibly modified 00078 # value of **options 00079 options = self.options 00080 00081 # That's the number of the question, not of the expressions it might 00082 # contain ! 00083 self.number = "" 00084 #if 'number_of_questions' in options: 00085 # self.number = options['number_of_questions'] 00086 00087 self.equation = Equation((RANDOMLY, q_kind)) 00088 00089 if 'expression_number' in options: 00090 self.equation.set_number(options['expression_number']) 00091 00092 00093 00094 00095 00096 00097 # -------------------------------------------------------------------------- 00098 ## 00099 # @brief Returns the text of the question as a str 00100 def text_to_str(self): 00101 M = self.machine 00102 00103 result = M.write_math_style2(M.type_string(self.equation, 00104 display_name='OK')) 00105 result += M.write_new_line() 00106 00107 return result 00108 00109 00110 00111 00112 00113 00114 # -------------------------------------------------------------------------- 00115 ## 00116 # @brief Returns the answer of the question as a str 00117 def answer_to_str(self): 00118 M = self.machine 00119 00120 return M.write(self.equation.auto_resolution()) 00121 00122 00123 00124 00125