#!/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_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$") % (nb1,
operateur, nb2))
cor.append(_("\\item $%s %s %s = \\mathbf{%s}$") % (nb1,
operateur, nb2, tot))
quiz_txt = ("%s %s %s = $$ {1:NUMERICAL:=%s}
\n" %
(nb1, operateur, nb2, TeX_quiz(tot,1)))
elif nbaleatoire > 0:
exo.append(_("\\item $%s %s \\ldots\\ldots = %s$") % (nb1,
operateur, tot))
cor.append(_("\\item $%s %s \\mathbf{%s} = %s$") % (nb1,
operateur, nb2, tot))
quiz_txt = ("%s %s $$ {1:NUMERICAL:=%s} $$ = %s $$
\n" %
(nb1, operateur, TeX_quiz(nb2.replace("\\left( ","").replace(",",".").replace("\\right)",""),1), tot))
else:
exo.append(_("\\item $\\ldots\\ldots %s %s = %s$") % (operateur,
nb2, tot))
cor.append(_("\\item $\\mathbf{%s} %s %s = %s$") % (nb1,
operateur, nb2, tot))
quiz_txt = ("$${1:NUMERICAL:=%s} $$%s %s = %s$$
\n" %
(TeX_quiz(nb1,1), 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 div(pyromax):
(a, b) = (Arithmetique.valeur_alea(-pyromax, pyromax), Arithmetique.valeur_alea(-pyromax,
pyromax))
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"Calcul mental - Quatrième")
quiz_exo_cor = _(u"Effectuer sans calculatrice :
\n")
quiz_exo_cor += u'
\n' modules = (plus, moins, plus, div) calculs = [i for i in range(20)] for i in range(20): j = random.randrange(0, len(calculs)) (a, b) = modules[calculs[j] // 5](10) if calculs[j] // 5 == 0: quiz_exo_cor += (u"$$%s) \\; "%(i+1) + choix_trou(a, tex_coef(b, '', bpn=1), a + b, '+', exo, cor)) if calculs[j] // 5 == 1: quiz_exo_cor += (u"$$%s) \\; "%(i+1) + choix_trou(a, tex_coef(b, '', bpn=1), a - b, '-', exo, cor)) if calculs[j] // 5 == 2: quiz_exo_cor += (u"$$%s) \\; "%(i+1) + choix_trou(a, tex_coef(b, '', bpn=1), a * b, '\\, \\cdot \\,', exo, cor)) if calculs[j] // 5 == 3: quiz_exo_cor += (u"$$%s) \\; "%(i+1) + choix_trou(a, tex_coef(b, '', bpn=1), a // b, '\\, : \\,', exo, cor)) calculs.pop(j) if i+1 == 7 or i+1 == 14: quiz_exo_cor += u" | \n" exo.extend([" \\end{enumerate}", "\\end{multicols}"]) cor.extend([" \\end{enumerate}", "\\end{multicols}"]) quiz_exo_cor += u" |