#!/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
#
from ..outils.Arithmetique import pgcd, valeur_alea
from ..outils.Affichage import decimaux, tex_coef, decimaux_quiz
from random import choice, randrange
import string
def tex_proprietes_val(exp_max, nb_max, type):
"""
Renvoie des valeurs pour l'exercice sur les propriétés des puissances
@param exp_max: valeur maximale pour les exposants
@type exp_max: Integer
@param nb_max: Valeur maximale pour les nombres
@type nb_max: integer
@param type: 0 : 2 exposants et 1 nombre ; 1 : 1 exposant et 2 nombres
@type type: integer
"""
if type:
while 1:
nb1 = randrange(2, nb_max)
nb2 = randrange(2, nb_max)
exp1 = randrange(2, exp_max)
exp2 = exp1
if nb1 != nb2:
break
else:
while 1:
nb1 = randrange(2, nb_max)
nb2 = nb1
exp1 = randrange(2, exp_max)
exp2 = randrange(2, exp_max)
if exp1 != exp2:
break
return (nb1, exp1, nb2, exp2)
def tex_proprietes():
exo = ["\\exercice",
_(u"Compléter par un nombre de la forme $a^n$ avec $a$ et $n$ entiers :"),
"\\begin{multicols}{3}", " \\noindent%",
" \\begin{enumerate}"]
cor = ["\\exercice*",
_(u"Compléter par un nombre de la forme $a^n$ avec $a$ et $n$ entiers :"),
"\\begin{multicols}{3}", " \\noindent%",
" \\begin{enumerate}"]
quiz = [u"cloze"]
quiz_nom = _(u"Puissances: Propriétés")
quiz_exo_cor = _(u"Écris-les dans une seule puissance de la forme $$a^n$$ avec numéros entiers:
\n")
quiz_exo_cor += u'
\n'
lexos = [0, 1, 2, 3, 0, 1, 2, 3, 0]
#0: a^n*a^p ; 1: (a^n)^p ; 2:a^n/a^p ; 3: a^n*b^n
for i in range(len(lexos)):
j = lexos.pop(randrange(len(lexos)))
if j == 3:
lval = tex_proprietes_val(12, 12, 1)
exo.append(_("\\item $%s^{%s} \\times %s^{%s} = \\dotfill$") %
lval)
cor.append(_("\\item $%s^{%s}\\times%s^{%s}=") % lval)
cor.append(_("$(%s\\times%s)^{%s}=") % (lval[0], lval[2], lval[1]))
cor.append("\\mathbf{%s^{%s}}$" % (lval[0] * lval[2], lval[1]))
quiz_exo_cor += (u"$$%s) \\; "%(i+1))+(u"%s^{%s}\\cdot%s^{%s}=$$" % lval)
quiz_exo_cor += (u"{1:NUMERICAL:=%s}{1:NUMERICAL:=%s} \n" % (lval[0] * lval[2], lval[1])) else: lval = tex_proprietes_val(12, 12, 0) if j == 0: exo.append(_("\\item $%s^{%s}\\times%s^{%s}=\\dotfill$") % lval) cor.append(_("\\item $%s^{%s}\\times%s^{%s}=") % lval) cor.append("$%s^{%s+%s}=" % (lval[0], lval[1], lval[3])) cor.append("\\mathbf{%s^{%s}}$" % (lval[0], lval[1] + lval[3])) quiz_exo_cor += (u"$$%s) \\; "%(i+1))+(u"%s^{%s}\\cdot%s^{%s}=$$" % lval) quiz_exo_cor += (u"{1:NUMERICAL:=%s}{1:NUMERICAL:=%s} \n" % (lval[0], lval[1] + lval[3])) elif j == 1: exo.append(_("\\item $(%s^{%s})^{%s}=\\dotfill$") % (lval[0], lval[1], lval[3])) cor.append("\\item $(%s^{%s})^{%s}=" % (lval[0], lval[1], lval[3])) cor.append(_("$%s^{%s\\times%s}=") % (lval[0], lval[1], lval[3])) cor.append("\\mathbf{%s^{%s}}$" % (lval[0], lval[1] * lval[3])) quiz_exo_cor += (u"$$%s) \\; (%s^{%s})^{%s}=$$" % (i+1, lval[0], lval[1], lval[3])) quiz_exo_cor += (u"{1:NUMERICAL:=%s}{1:NUMERICAL:=%s} \n" % (lval[0], lval[1] * lval[3])) elif j == 2: while lval[1] - lval[3] < 3: lval = tex_proprietes_val(12, 12, 0) exo.append(_("\\item $\\dfrac{%s^{%s}}{%s^{%s}}=\\dotfill$") % lval) cor.append("\\item $\\dfrac{%s^{%s}}{%s^{%s}}=" % lval) cor.append("$%s^{%s-%s}=" % (lval[0], lval[1], lval[3])) cor.append("\\mathbf{%s^{%s}}$" % (lval[0], lval[1] - lval[3])) quiz_exo_cor += (u"$$%s) \\; "%(i+1))+(u"\\frac{%s^{%s}}{%s^{%s}}=$$" % lval) quiz_exo_cor += (u"{1:NUMERICAL:=%s}{1:NUMERICAL:=%s} \n" % (lval[0], lval[1] - lval[3])) if i == 2 or i == 5: exo.append("\\stepcounter{nocalcul}\\columnbreak %") cor.append("\\stepcounter{nocalcul}\\columnbreak %") # <---MIO quiz_exo_cor += u" | \n" else: exo.append("\\stepcounter{nocalcul}%") cor.append("\\stepcounter{nocalcul}%") exo.append("\\end{enumerate}") exo.append("\\end{multicols}\n") cor.append("\\end{enumerate}") cor.append("\\end{multicols}\n") quiz_exo_cor += u" |
\n'
lexos = [0, 1, 2, 3, 0, 1, 2, 3]
#0: a^n*a^p ; 1: (a^n)^p ; 2:a^n/a^p
for i in range(len(lexos)):
ii = i
lexp = [randrange(-6, 6) for i in range(2)]
j = lexos.pop(randrange(len(lexos)))
# FIXME : À finir
if j == 0:
while abs(lexp[0] + lexp[1]) > 10:
lexp = [randrange(-6, 6) for i in range(2)]
exo.append(_("\\item $10^{%s} \\times 10^{%s} = \\dotfill$") %
tuple(lexp))
cor.append(_("\\item $10^{%s}\\times 10^{%s}=") % tuple(lexp))
cor.append("10^{%s+%s}=" % (lexp[0], tex_coef(lexp[1],
'', bpn=1, cero=1)))
cor.append("10^{%s}=%s$" % (lexp[0] + lexp[1],
decimaux(10 ** (lexp[0] + lexp[1]), 1)))
quiz_exo_cor += (u"$$%s) \\; "%(ii+1))+(u"10^{%s} \\cdot 10^{%s} = 10$$" %
tuple(lexp))
# Cuando se soluciones bug-quiz-cloze-coma cambiar SHORTANSWER por NUMERICAL y tipo de decimaux_quiz
quiz_exo_cor += (u"{1:NUMERICAL:=%s}$$\\,=$${1:SHORTANSWER:%s100%s%s} \n" % (lexp[0] + lexp[1], "%", "%", decimaux_quiz(10 ** (lexp[0] + lexp[1]), 0))) elif j == 1: while abs(lexp[0] * lexp[1]) > 10: lexp = [randrange(-6, 6) for i in range(2)] exo.append(_("\\item $(10^{%s})^{%s}=\\dotfill$") % (lexp[0], lexp[1])) cor.append("\\item $(10^{%s})^{%s}=" % tuple(lexp)) cor.append(_("10^{%s \\times %s}=") % (lexp[0], tex_coef(lexp[1], '', bpn=1, cero=1))) cor.append("10^{%s}=%s$" % (lexp[0] * lexp[1], decimaux(10 ** (lexp[0] * lexp[1]), 1))) quiz_exo_cor += (u"$$%s) \\; "%(ii+1))+(u"(10^{%s})^{%s}= 10$$" % (lexp[0], lexp[1])) # Cuando se soluciones bug-quiz-cloze-coma cambiar SHORTANSWER por NUMERICAL y tipo de decimaux_quiz quiz_exo_cor += (u"{1:NUMERICAL:=%s}$$\\,=$${1:SHORTANSWER:%s100%s%s} \n" % (lexp[0] * lexp[1], "%", "%", decimaux_quiz(10 ** (lexp[0] * lexp[1]), 0))) else: while abs(lexp[0] - lexp[1]) > 10: lexp = [randrange(-6, 6) for i in range(2)] exo.append(_("\\item $\\dfrac{10^{%s}}{10^{%s}}=\\dotfill$") % tuple(lexp)) cor.append("\\item $\\dfrac{10^{%s}}{10^{%s}}=" % tuple(lexp)) cor.append("10^{%s-%s}=" % (lexp[0], tex_coef(lexp[1], '', bpn=1, cero=1))) cor.append("10^{%s}=%s$" % (lexp[0] - lexp[1], decimaux(10 ** (lexp[0] - lexp[1]), 1))) quiz_exo_cor += (u"$$%s) \\; "%(ii+1))+(u"\\frac{10^{%s}}{10^{%s}}= 10$$" % tuple(lexp)) # Cuando se soluciones bug-quiz-cloze-coma cambiar SHORTANSWER por NUMERICAL y tipo de decimaux_quiz quiz_exo_cor += (u"{1:NUMERICAL:=%s}$$\\,=$${1:SHORTANSWER:%s100%s%s} \n" % (lexp[0] - lexp[1], "%", "%", decimaux_quiz(10 ** (lexp[0] - lexp[1]), 0))) if ii == 3: exo.append("\\stepcounter{nocalcul}\\columnbreak %") cor.append("\\stepcounter{nocalcul}\\columnbreak %") # <---MIO quiz_exo_cor += u" | \n" else: exo.append("\\stepcounter{nocalcul}%") cor.append("\\stepcounter{nocalcul}%") exo.append("\\end{enumerate}") exo.append("\\end{multicols}\n") cor.append("\\end{enumerate}") cor.append("\\end{multicols}\n") quiz_exo_cor += u" |
\n'
for i in range(6):
a = val_sc()
exp = int(floor(log10(a)))
a_sc = (a * 1.) / 10 ** exp
s_a = decimaux(a, 1)
s_a_sc = decimaux(a_sc, 1)
if randrange(2): # forme : a=a_sc*...
exo.append(_("\\item $%s=%s\\times\\dotfill$") % (s_a,
s_a_sc))
cor.append(_("\\item $%s=%s\\times\\mathbf{10^{%s}}$") % (s_a,
s_a_sc, decimaux(exp, 1)))
quiz_exo_cor += (u"$$%s) \\; %s=%s\\, \\cdot\\, 10$$" %
(i+1, s_a, s_a_sc))
quiz_exo_cor += (u"{1:NUMERICAL:=%s} \n" % decimaux_quiz(exp, 1)) else: # forme : a_sc*...=a exo.append(_("\\item $%s\\times\\dotfill=%s$") % (s_a_sc, s_a)) cor.append(_("\\item $%s\\times\\mathbf{10^{%s}}=%s$") % (s_a_sc, decimaux(exp, 1), s_a)) quiz_exo_cor += (u"$$%s) \\; %s\\, \\cdot\\, 10$$" % (i+1, s_a_sc)) quiz_exo_cor += (u"{1:NUMERICAL:=%s}$$=%s$$ \n" % (decimaux_quiz(exp, 1), s_a)) if i == 2: exo.append("\\stepcounter{nocalcul}\\columnbreak %") cor.append("\\stepcounter{nocalcul}\\columnbreak %") # <---MIO quiz_exo_cor += u" | \n" else: exo.append("\\stepcounter{nocalcul}%") cor.append("\\stepcounter{nocalcul}%") exo.append("\\end{enumerate}") exo.append("\\end{multicols}\n") cor.append("\\end{enumerate}") cor.append("\\end{multicols}\n") quiz_exo_cor += u" |