#!/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 # import random def valeurs_diviseurs(): diviseurs = [2, 3, 5, 9, 10] liste = [] for i in range(5): liste.append(diviseurs.pop(random.randrange(len(diviseurs))) * random.randrange(11, 100)) return liste def liste_diviseurs(l): diviseurs = (2, 3, 5, 9, 10) reponse = [] reponse_quiz = [] for i in range(len(l)): reponse.extend([[l[i]]]) reponse_quiz.extend([[l[i]]]) for j in range(len(diviseurs)): if l[i] % diviseurs[j]: # n'est pas divisible reponse[i].append("$\\Square$") reponse_quiz[i].append("") else: reponse[i].append("$\\CheckedBox$") reponse_quiz[i].append(str(diviseurs[j])) return reponse, reponse_quiz, diviseurs def Divisible(): l = valeurs_diviseurs() reponse = liste_diviseurs(l)[0] reponse_quiz = liste_diviseurs(l)[1] diviseurs = liste_diviseurs(l)[2] n_div = len(diviseurs) exo = ["\\exercice", _(u'Cocher les bonnes réponses :\\par')] cor = ["\\exercice*", _(u'Cocher les bonnes réponses :\\par')] quiz = [u"multichoice"] exo.append(_(u"\\begin{tabular}{c@{ est divisible : \kern1cm}r@{ par 2\\kern1cm}r@{ par 3\\kern1cm}r@{ par 5\\kern1cm}r@{ par 9\\kern1cm}r@{ par 10}}")) cor.append(_(u"\\begin{tabular}{c@{ est divisible : \kern1cm}r@{ par 2\\kern1cm}r@{ par 3\\kern1cm}r@{ par 5\\kern1cm}r@{ par 9\\kern1cm}r@{ par 10}}")) for i in range(len(l)): quiz_cor = [] exo.append("%s & $\\square$ & $\\square$ & $\\square$ & $\\square$ & $\\square$ \\\\" % l[i]) cor.append("%s & %s & %s & %s & %s & %s \\\\" % tuple(reponse[i])) quiz_nom = _(u'Divisible entre 2, 3, 5, 9, 10') quiz_exo = (_(u"Marque l'ou les guichets lesquels soient diviseurs de $$%s$$") % l[i]) n_div_i = n_div - reponse_quiz[i].count('') for j in range(n_div): if str(diviseurs[j]) == reponse_quiz[i][j+1]: quiz_cor.append([100.0/n_div_i, '$$'+str(diviseurs[j])+'$$']) else: quiz_cor.append([0, '$$'+str(diviseurs[j])+'$$']) quiz.append([quiz_nom, quiz_exo, quiz_cor]) exo.append("\\end{tabular}") cor.append("\\end{tabular}") return (exo, cor, quiz)