#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Pyromaths
# Un programme en Python qui permet de créer des fiches d'exercices types de
# mathématiques niveau collège ainsi que leur corrigé en LaTeX.
# Copyright (C) 2006 -- Jérôme Ortais (jerome.ortais@pyromaths.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
#----------------------------------------------------------------------
# Pyromaths : Poser des opérations
#----------------------------------------------------------------------
from ..outils import Arithmetique
from ..outils.Affichage import TeX, tex_coef, TeX_quiz
import random
def choix_trou(nb1, nb2, tot, operateur, exo, cor):
nbaleatoire = random.randrange(4)
if nbaleatoire > 1:
exo.append(_("\\item $%s %s %s = \\ldots\\ldots\\ldots$") % (nb1,
operateur, nb2))
cor.append("\\item $%s %s %s = \\mathbf{%s}$" % (nb1,
operateur, nb2, tot))
## Cambia a NUMERICAL cuando el bug de quiz se solucione, también el ,0 a ,1
quiz_txt = ("%s %s %s = $$ {1:SHORTANSWER:%s100%s%s}
\n" %
(nb1, operateur, nb2, "%", "%", TeX_quiz(tot,0)))
elif nbaleatoire > 0:
exo.append(_("\\item $%s %s \\ldots\\ldots\\ldots = %s$") % (nb1,
operateur, tot))
cor.append("\\item $%s %s \\mathbf{%s} = %s$" % (nb1,
operateur, nb2, tot))
## Cambia a NUMERICAL cuando el bug de quiz se solucione, también el ,0 a ,1
quiz_txt = ("%s %s $$ {1:SHORTANSWER:%s100%s%s} $$ = %s $$
\n" %
(nb1, operateur, "%", "%", TeX_quiz(nb2.replace("\\left( ","").replace(",",".").replace("\\right)",""),0), tot))
else:
exo.append(_("\\item $\\ldots\\ldots\\ldots %s %s = %s$") % (operateur,
nb2, tot))
cor.append("\\item $\\mathbf{%s} %s %s = %s$" % (nb1,
operateur, nb2, tot))
## Cambia a NUMERICAL cuando el bug de quiz se solucione, también el ,0 a ,1
quiz_txt = ("$${1:SHORTANSWER:%s100%s%s} $$%s %s = %s$$
\n" %
("%", "%", TeX_quiz(nb1,0), operateur, nb2, tot))
return quiz_txt
def plus(pyromax):
(a, b) = (Arithmetique.valeur_alea(-pyromax, pyromax), Arithmetique.valeur_alea(-pyromax,
pyromax))
return (a, b)
def moins(pyromax):
(a, b) = (Arithmetique.valeur_alea(-pyromax, pyromax), Arithmetique.valeur_alea(-pyromax,
pyromax))
return (a + b, a)
def plus_dec(pyromax):
(a, b) = (Arithmetique.valeur_alea(-10*pyromax, 10*pyromax)/10.0, Arithmetique.valeur_alea(-10*pyromax, 10*pyromax)/10.0)
return (a, b)
def moins_dec(pyromax):
(a, b) = (Arithmetique.valeur_alea(-10*pyromax, 10*pyromax)/10.0, Arithmetique.valeur_alea(-10*pyromax, 10*pyromax)/10.0)
return (a + b, a)
def main():
exo = ["\\exercice", _(u"Effectuer sans calculatrice :"),
"\\begin{multicols}{3}\\noindent", " \\begin{enumerate}"]
cor = ["\\exercice*", _(u"Effectuer sans calculatrice :"),
"\\begin{multicols}{3}\\noindent", " \\begin{enumerate}"]
quiz = [u"cloze"]
quiz_nom = _(u"Sommes et soustractions relatives")
quiz_exo_cor = _(u"Réalise sans calculatrice :
\n")
quiz_exo_cor += u'
\n' modules = (plus, moins, ) modules_dec= (plus_dec, moins_dec, ) calculs = [i for i in range(20)] random.shuffle(calculs) for j in range(4): (a, b) = modules[calculs[j] // 10](10) quiz_exo_cor += (u"$$%s) \\; "%(j+1) + choix_trou(a, tex_coef(b, '', bpn=1), a + b, '+', exo, cor)) for j in range(4,14): (a, b) = modules[calculs[j] // 10](10) if calculs[j] // 10 == 0: quiz_exo_cor += (u"$$%s) \\; "%(j+1) + choix_trou(a, tex_coef(b, '', bpn=1), a + b, '+', exo, cor)) if calculs[j] // 10 == 1: quiz_exo_cor += (u"$$%s) \\; "%(j+1) + choix_trou(a, tex_coef(b, '', bpn=1), a - b, '-', exo, cor)) if j+1 == 7 or j+1 == 14: quiz_exo_cor += u" | \n" for j in range(14,20): (a, b) = modules_dec[calculs[j] // 10](10) if calculs[j] // 10 == 0: quiz_exo_cor += (u"$$%s) \\; "%(j+1) + choix_trou(TeX(a), tex_coef(b, '', bpn=1), TeX(a + b), '+', exo, cor)) if calculs[j] // 10 == 1: quiz_exo_cor += (u"$$%s) \\; "%(j+1) + choix_trou(TeX_quiz(a), tex_coef(b, '', bpn=1), TeX(a - b), '-', exo, cor)) exo.extend([" \\end{enumerate}", "\\end{multicols}"]) cor.extend([" \\end{enumerate}", "\\end{multicols}"]) quiz_exo_cor += u" |