#!/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 : Initiation au calcul littéral
#----------------------------------------------------------------------
from ..outils import Arithmetique
from ..outils.Affichage import tex_coef
from ..outils.Priorites3 import texify, priorites
import random
#from ..outils import Priorites3
from ..classes.PolynomesCollege import Polynome
def valeurs_reduire():
"""Travail sur les bases du calcul littéral en quatrième"""
var = "abcdfghkmnpqrstuvwxyz"
var = var[random.randrange(len(var))]
op = "+*-*"[random.randrange(4)]
if op == "*":
deg1 = random.randrange(3)
if deg1 == 2: deg2=0
elif deg1 == 1: deg2 = random.randrange(2)
else: deg2 = random.randrange(1, 3)
else:
deg1 = random.randrange(1, 3)
deg2 = [i for i in range(3)]
deg2.extend([deg1]*7)
random.shuffle(deg2)
deg2 = deg2.pop(random.randrange(len(deg2)))
a1, a2 = 0, 0
while not a1 or not a2:
a1 = random.randrange(-10, 11)
a2 = random.randrange(-10, 11)
p1 = "Polynome(\"%s%s^%s\")" % (a1, var, deg1)
p2 = "Polynome(\"%s%s^%s\")" % (a2, var, deg2)
return p1 + op + p2, var
def quiz_txt(quiz_cor, var):
m_txt = ""
if isinstance(quiz_cor, int):
m_txt += (u"{1:NUMERICAL:=0} $$%s+$$ {1:NUMERICAL:=%s}" %
(var, quiz_cor))
else:
ter_indp = 0 # Esto lo he puesto para que añada el término independiente ceo
for i in range(len(quiz_cor)):
if i < len(quiz_cor)-1:
signe_plus = "+"
else:
signe_plus = ""
if quiz_cor[i][1] > 1:
ter_indp += 1
m_txt += (u"{1:NUMERICAL:=%s} $$%s^%s%s$$" %
(quiz_cor[i][0], var, quiz_cor[i][1], signe_plus))
elif quiz_cor[i][1] == 1:
ter_indp += 1
m_txt += (u"{1:NUMERICAL:=%s} $$%s%s$$" %
(quiz_cor[i][0], var, signe_plus))
else:
ter_indp += 1
m_txt += (u"{1:NUMERICAL:=%s}" %
(quiz_cor[i][0]))
if ter_indp == 1:
m_txt += (u" $$+$${1:NUMERICAL:=0}")
return m_txt
def reduire():
"""Travail sur les bases du calcul littéral en quatrième"""
exo = ["\\exercice", _(u"Réduire, si possible, les expressions suivantes :"),
"\\begin{multicols}{3}\\noindent", " \\begin{enumerate}"]
cor = ["\\exercice*", _(u"Réduire, si possible, les expressions suivantes :"),
"\\begin{multicols}{3}\\noindent", " \\begin{enumerate}"]
quiz = [u"cloze"]
quiz_nom = _(u"Monômes: Calculs basiques")
quiz_exo_cor = _(u"Réduit, si est possible, les suivantes expressions :
\n")
quiz_exo_cor += u'
\n'
for i in range(9):
a, var = valeurs_reduire()
solve = [a]
exo.append("\\item $\\thenocalcul = " + texify(solve)[0] + "$")
cor.append("\\item $\\thenocalcul = " + texify(solve)[0] + "$")
solve = priorites(a)
quiz_cor = eval(solve[len(solve)-1][0]) # NO CAMBIAR DE LUGAR
if not isinstance(quiz_cor, int):
quiz_cor = quiz_cor.ordonne()
solve.insert(0, a)
solve = texify(solve)
if len(solve)>1:
for e in solve[1:]:
cor.append("\\[\\thenocalcul = " + e + "\\]")
exo.append("\\stepcounter{nocalcul}")
cor.append("\\stepcounter{nocalcul}")
quiz_exo_cor += (u"$$%s) \\; %s $$ \n" % (i+1, solve[0])) quiz_exo_cor += (_(u"Réponse: %s \n") % (quiz_txt(quiz_cor, var))) if i+1 == 5: quiz_exo_cor += u" | \n" exo.extend([" \\end{enumerate}", "\\end{multicols}"]) cor.extend([" \\end{enumerate}", "\\end{multicols}"]) quiz_exo_cor += u" |
\n'
for i in range(6):
if i < 3: a, var = valeurs_reduire_somme()
else: a, var = valeurs_reduire_sommeprod()
solve = [a]
exo.append("\\item $\\thenocalcul = " + texify(solve)[0] + "$")
cor.append("\\item $\\thenocalcul = " + texify(solve)[0] + "$")
solve = priorites(a)
quiz_cor = eval(solve[len(solve)-1][0]) # NO CAMBIAR DE LUGAR
solve.insert(0, a)
solve = texify(solve)
if len(solve)>1:
for e in solve[1:]:
cor.append("\\[\\thenocalcul = " + e + "\\]")
exo.append("\\stepcounter{nocalcul}")
cor.append("\\stepcounter{nocalcul}")
quiz_exo_cor += (u"$$%s) \\; %s $$ \n" % (i+1, solve[0])) quiz_exo_cor += (_(u"Réponse: %s \n") % (quiz_txt(quiz_cor, var))) if i+1 == 3: quiz_exo_cor += u" | \n" exo.extend([" \\end{enumerate}", "\\end{multicols}"]) cor.extend([" \\end{enumerate}", "\\end{multicols}"]) quiz_exo_cor += u" |