#!/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 random import randint, shuffle from ..outils.Affichage import decimaux, decimaux_quiz def valide_hasard(): """renvoie un nombre float non multiple de 10000""" nbre, unite = randint(1000,100000), randint(1,9) return float(nbre)*10+unite def ArrondirNombreDecimal(): """Crée et corrige un exercice d'arrondis avec les encadrements.""" hasard = [valide_hasard() for i in range(4)] precision = [_(u'au millième'), _(u'au centième'), _(u'au dixième'), _(u'à l\'unité'), _(u'à la dizaine'), _(u'à la centaine'), _(u'au millier'), _(u'à la dizaine de milliers')] choix = [(i,j) for i in range(8) for j in range(3)] shuffle(choix) choix_precision = [choix[i][0] for i in range(4)] choix_supinf = [choix[i][1] for i in range(4)] ## choix_precision = [randint(0, 7), randint(0, 7), randint(0, 7), ## randint(0, 7)] ## choix_supinf = [randint(0, 2), randint(0, 2), randint(0, 2), randint(0, 2)] supinf = ['', _(u' par défaut'), _(u' par excès')] #FIXME #Arrondir n'est pas synonyme de valeur approchée #Valeur approchée par excès  #Valeur approchée par défaut  #Arrondi = la « meilleure » valeur approchée #et ne paraît employé ici correctement nombres = [(hasard[0])/(10**(-choix_precision[0]+4)), (hasard[1])/(10**(-choix_precision[1]+4)), (hasard[2])/(10**(-choix_precision[2]+4)), (hasard[3])/(10**(-choix_precision[3]+4))] exo = ["\\exercice", '\\begin{enumerate}'] cor = ["\\exercice*", '\\begin{enumerate}'] quiz = [u"cloze"] quiz_nom = _(u"Arrondissages de décimale") quiz_exo_cor = _(u"Réalise les suivants rapprochements décimaux:
\n") for k in range(4): exo.append( _(u"\\item Arrondir ") + decimaux(nombres[k]) + " " + precision[choix_precision[k]] + supinf[choix_supinf[k]] + '.' ) arrondi = round(nombres[k], -choix_precision[k]+3) if (arrondi > nombres[k]): defaut = arrondi - 10**(choix_precision[k]-3) exc = arrondi if (arrondi <= nombres[k]): defaut = arrondi exc = arrondi + 10**(choix_precision[k]-3) if (choix_supinf[k] == 0): solution = arrondi elif (choix_supinf[k] == 1): solution = defaut elif (choix_supinf[k] == 2): solution = exc cor.append( _(u'\\item L\'encadrement de ') + decimaux(nombres[k]) + ' ' + precision[choix_precision[k]] + _(u' est :\\par') ) cor.append( decimaux(defaut) + ' < ' + decimaux(nombres[k]) + ' < ' + decimaux(exc) + '\\par' ) cor.append( _(u'On en déduit que son arrondi ') + precision[choix_precision[k]] + ' ' + supinf[choix_supinf[k]] + _(u' est : ') + decimaux(solution) + '.') quiz_exo_cor += (u"$$%s) \\;$$"%(k+1) + _(u'L\'arrondissage de $$') + decimaux_quiz(nombres[k]) + "$$ " + precision[choix_precision[k]] + supinf[choix_supinf[k]]) ## Cambia a NUMERICAL cuando el bug de quiz se solucione, también el ,0 a ,1 quiz_exo_cor += (_(u" est {1:SHORTANSWER:%s100%s%s}
\n") % ("%", "%", decimaux_quiz(solution,0))) quiz.append([quiz_nom, quiz_exo_cor[0:(len(quiz_exo_cor)-1)], ""]) exo.append("\\end{enumerate}") cor.append("\\end{enumerate}") return (exo, cor, quiz)