Example #1
0
def classer(exo, cor):
    lnb = choix_nombres()
    random.shuffle(lnb)
    if random.randrange(2):
        ordre = "croissant"
    else:
        ordre = u"décroissant"
    exo.append(
        "\\item Classer les nombres suivants dans l'ordre %s.\\par    " %
        ordre)
    cor.append(
        "\\item Classer les nombres suivants dans l'ordre %s.\\par    " %
        ordre)
    phrase = ""
    for i in range(len(lnb)):
        if i:
            phrase += " \\kern1cm ; \\kern1cm "
        phrase += Affichage.decimaux(lnb[i], 0)
    exo.append(phrase)
    cor.append(phrase + "\\par")
    lnb.sort()
    if ordre == "croissant":
        ordre = "\\textless"
    else:
        ordre = "\\textgreater"
        lnb.reverse()
    phrase = ""
    for i in range(len(lnb)):
        if i:
            phrase += " \\kern1cm %s \\kern1cm " % ordre
        phrase += Affichage.decimaux(lnb[i], 0)
    cor.append(phrase)
Example #2
0
def tex_conversion(exo, cor, exposant, u):
    """Écrit une question sur les conversions d'unités d'aires ou de volume
    et le corrigé au format LaTeX
    @param exo: fichier exercices
    @param cor: fichier corrige
    exposant = 2 ou 3 pour les aires ou les volumes
    """

    a = random.randint(101, 999)
    p = random.randint(-2, -1)
    while True:
        (div0, div1) = (random.randrange(6), random.randrange(7),)
        # Pas de mm³ par ce que ça sort du tableau
        if (div0 - div1) in [-2, -1, 1, 2]:
            # pas trop loin car ça fait de très longs nombres
            break
    nb0 = a * 10 ** p
    nb1 = nb0 * 10 ** (exposant * (div1 - div0))

    exo.append("\\item $\\unit[%s]{%s}=\\unit[\\dotfill]{%s}$" % 
            (Affichage.decimaux(nb0), u[div0], u[div1]))
    cor.append("\\item $\\unit[%s]{%s}=\\unit[%s]{%s}$\\vspace{1ex}\\par" % 
            (Affichage.decimaux(nb0), u[div0],
                Affichage.decimaux(nb1), u[div1]))

    return tex_tableau_conversion(div0, div1, nb0, u, exposant)
Example #3
0
def tex_conversion(exo, cor, exposant, u):
    """Écrit une question sur les conversions d'unités d'aires ou de volume
    et le corrigé au format LaTeX
    @param exo: fichier exercices
    @param cor: fichier corrige
    exposant = 2 ou 3 pour les aires ou les volumes
    """

    a = random.randint(101, 999)
    p = random.randint(-2, -1)
    while True:
        (div0, div1) = (
            random.randrange(6),
            random.randrange(7),
        )
        # Pas de mm³ par ce que ça sort du tableau
        if (div0 - div1) in [-2, -1, 1, 2]:
            # pas trop loin car ça fait de très longs nombres
            break
    nb0 = a * 10**p
    nb1 = nb0 * 10**(exposant * (div1 - div0))

    exo.append("\\item $\\unit[%s]{%s}=\\unit[\\dotfill]{%s}$" %
               (Affichage.decimaux(nb0), u[div0], u[div1]))
    cor.append(
        "\\item $\\unit[%s]{%s}=\\unit[%s]{%s}$\\vspace{1ex}\\par" %
        (Affichage.decimaux(nb0), u[div0], Affichage.decimaux(nb1), u[div1]))

    return tex_tableau_conversion(div0, div1, nb0, u, exposant)
Example #4
0
def classer(exo, cor):
    lnb = choix_nombres()
    random.shuffle(lnb)
    if random.randrange(2):
        ordre = "croissant"
    else:
        ordre = u"décroissant"
    exo.append("\\item Classer les nombres suivants dans l'ordre %s.\\par    " % 
             ordre)
    cor.append("\\item Classer les nombres suivants dans l'ordre %s.\\par    " % 
             ordre)
    phrase = ""
    for i in range(len(lnb)):
        if i:
            phrase += " \\kern1cm ; \\kern1cm "
        phrase += Affichage.decimaux(lnb[i], 0)
    exo.append(phrase)
    cor.append(phrase + "\\par")
    lnb.sort()
    if ordre == "croissant":
        ordre = "\\textless"
    else:
        ordre = "\\textgreater"
        lnb.reverse()
    phrase = ""
    for i in range(len(lnb)):
        if i:
            phrase += " \\kern1cm %s \\kern1cm " % ordre
        phrase += Affichage.decimaux(lnb[i], 0)
    cor.append(phrase)
Example #5
0
def EcritEnLettre(exo, cor):
    lnb = nombreATrouver()
    for i in range(8):
        exo.append("\\item " + Affichage.decimaux(lnb[i], 0) + 
                 " : \\dotfill")
        cor.append("\\item " + Affichage.decimaux(lnb[i], 0) + 
                " : ")
        cor.append(EcritNombreDecimal(lnb[i]) + '')
Example #6
0
def tex_units():
    """
    Écrit l'exercice sur les conversions d'unités et le corrigé au format
    LaTeX
    @param exo: fichier exercices
    @param cor: fichier corrige
    """

    exo = [
        "\\exercice", 'Effectuer les conversions suivantes :',
        '\\begin{multicols}{3}\\noindent', '\\begin{enumerate}'
    ]
    cor = [
        "\\exercice*",
        # paramétrage des flèches, ce paramétrage est limité à l'exercice
        # et ne modifie pas le paramétrage PSTricks du document car sa portée est limité par le groupe ouvert par "{"
        "{",
        PSSET_FLECHE,
        'Effectuer les conversions suivantes :',
        '\\begin{multicols}{2}\\noindent',
        '\\begin{enumerate}'
    ]

    # Construit les 6 questions de l'exercice
    for i in range(6):
        (a, p, unit, div0, div1) = valeurs_units()
        if unit:
            u = tuple([units[unit] for i in range(7)])
        else:
            u = tuple([units[unit] for i in range(6)])
        nb0 = Affichage.decimaux(a * 10**p, 0)
        nb1 = Affichage.decimaux(a * 10**((p + div1) - div0), 0)
        exo.append(
            "\\item %s~%s%s=\dotfill~%s%s" %
            (nb0, division[div0], units[unit], division[div1], units[unit]))
        cor.append("\\item %s~%s%s=%s~%s%s\\par" %
                   (nb0, division[div0], units[unit], nb1, division[div1],
                    units[unit]))
        nblist = [nb0[i] for i in range(len(nb0))]
        if nblist.count(','):
            chf_unite = nblist.index(',') - 1
            nblist.pop(chf_unite + 1)
        else:
            chf_unite = len(nblist) - 1

        tex_tableau(cor, div0, div1, u, nblist, chf_unite)

        cor.append("\\end{tabular}")
        cor.append("\\ncline{->}{virg0}{virg1}")

    exo.append('\\end{enumerate}')
    exo.append('\\end{multicols}')
    cor.append('\\end{enumerate}')
    cor.append('\\end{multicols}')
    # ferme le groupe limitant la portée de PSSET_FLECHE
    cor.append('{')
    return (exo, cor)
Example #7
0
def tex_units():
    """
    Écrit l'exercice sur les conversions d'unités et le corrigé au format
    LaTeX
    @param exo: fichier exercices
    @param cor: fichier corrige
    """

    exo = ["\\exercice", 'Effectuer les conversions suivantes :',
            '\\begin{multicols}{3}\\noindent', '\\begin{enumerate}']
    cor = ["\\exercice*",
            # paramétrage des flèches, ce paramétrage est limité à l'exercice
            # et ne modifie pas le paramétrage PSTricks du document car sa portée est limité par le groupe ouvert par "{"
           "{",
            PSSET_FLECHE,
           'Effectuer les conversions suivantes :',
            '\\begin{multicols}{2}\\noindent', '\\begin{enumerate}']

    # Construit les 6 questions de l'exercice
    for i in range(6):
        (a, p, unit, div0, div1) = valeurs_units()
        if unit:
            u = tuple([units[unit] for i in range(7)])
        else:
            u = tuple([units[unit] for i in range(6)])
        nb0 = Affichage.decimaux(a * 10 ** p, 0)
        nb1 = Affichage.decimaux(a * 10 ** ((p + div1) - div0),
                0)
        exo.append("\\item %s~%s%s=\dotfill~%s%s" % (nb0, division[div0],
                 units[unit], division[div1], units[unit]))
        cor.append("\\item %s~%s%s=%s~%s%s\\par" % (nb0, division[div0],
                 units[unit], nb1, division[div1], units[unit]))
        nblist = [nb0[i] for i in range(len(nb0))]
        if nblist.count(','):
            chf_unite = nblist.index(',') - 1
            nblist.pop(chf_unite + 1)
        else:
            chf_unite = len(nblist) - 1

        tex_tableau(cor, div0, div1, u, nblist, chf_unite)

        cor.append("\\end{tabular}")
        cor.append("\\ncline{->}{virg0}{virg1}")

    exo.append('\\end{enumerate}')
    exo.append('\\end{multicols}')
    cor.append('\\end{enumerate}')
    cor.append('\\end{multicols}')
    # ferme le groupe limitant la portée de PSSET_FLECHE
    cor.append('{')
    return (exo, cor)
Example #8
0
def tex_place_virgule(exo, cor):
    """
    Écrit un exercices demandant de placer une virgule dans un nombre.
    @param exo: fichier exerices
    @param cor:fichier corrigé
    """

    valeurs_index = [0, 1, 2, 3, 4, 5, 6]
    nb = valeurs_decimaux()
    exo.append(
        u"Placer une virgule (en ajoutant éventuellement des zéros) dans\
            le nombre %s de telle sorte que :" % nb)
    exo.append('\\begin{enumerate}')
    cor.append(
        u"Placer une virgule (en ajoutant éventuellement des zéros) dans\
            le nombre %s de telle sorte que :" % nb)
    cor.append('\\begin{enumerate}')
    for i in range(6):
        dec = [str(nb)[i] for i in range(len(str(nb)))]
        index_dec = random.randrange(6)
        index_valeurs = valeurs_index.pop(random.randrange(len(valeurs_index)))
        exo.append(u"\\item le chiffre %s soit le chiffre des %s : " \
                 % (dec[index_dec], valeurs[index_valeurs]))
        cor.append(u"\\item le chiffre %s soit le chiffre des %s : " \
                 % (dec[index_dec], valeurs[index_valeurs]))
        resultat = ecrit_nombre_decimal(dec, (index_dec + 4) - index_valeurs)
        exo.append('\\dotfill')
        cor.append(Affichage.decimaux(resultat, 0) + '')
    exo.append('\\end{enumerate}')
    cor.append('\\end{enumerate}')
Example #9
0
def tex_place_virgule(exo, cor):
    """
    Écrit un exercices demandant de placer une virgule dans un nombre.
    @param exo: fichier exerices
    @param cor:fichier corrigé
    """

    valeurs_index = [0, 1, 2, 3, 4, 5, 6]
    nb = valeurs_decimaux()
    exo.append(u"Placer une virgule (en ajoutant éventuellement des zéros) dans\
            le nombre %s de telle sorte que :" % nb)
    exo.append('\\begin{enumerate}')
    cor.append(u"Placer une virgule (en ajoutant éventuellement des zéros) dans\
            le nombre %s de telle sorte que :" % nb)
    cor.append('\\begin{enumerate}')
    for i in range(6):
        dec = [str(nb)[i] for i in range(len(str(nb)))]
        index_dec = random.randrange(6)
        index_valeurs = valeurs_index.pop(random.randrange(len(valeurs_index)))
        exo.append(u"\\item le chiffre %s soit le chiffre des %s : " \
                 % (dec[index_dec], valeurs[index_valeurs]))
        cor.append(u"\\item le chiffre %s soit le chiffre des %s : " \
                 % (dec[index_dec], valeurs[index_valeurs]))
        resultat = ecrit_nombre_decimal(dec, (index_dec + 4) - 
                index_valeurs)
        exo.append('\\dotfill')
        cor.append(Affichage.decimaux(resultat, 0) + '')
    exo.append('\\end{enumerate}')
    cor.append('\\end{enumerate}')
Example #10
0
def triangle_base(dim, n_fig):
    """Dessine en psTricks un triangle avec une base horizontale ou verticale
    dans une boite de dimensions dim et numérote la figure avec n_fig"""
    sommets = [(0, 0), (dim[0], 0), dim, (0, dim[1])]
    s0 = random.randrange(4)
    s1 = (s0 + 1) % 4
    x0, x1 = sommets[(s0 + 2) % 4][0], sommets[(s0 + 3) % 4][0]
    y0, y1 = sommets[(s0 + 2) % 4][1], sommets[(s0 + 3) % 4][1]
    if x0 > x1: x0, x1 = x1, x0
    if y0 > y1: y0, y1 = y1, y0
    if x0 != x1: x0 = random.randrange(x0 + 1, x1)
    if y0 != y1: y0 = random.randrange(y0 + 1, y1)
    s2 = (x0, y0)
    s0, s1 = sommets[s0], sommets[s1]
    f = "\\pspolygon[fillstyle=hlines]%s%s%s\n" % (s0, s1,
            s2)
    f += "\\rput(%.2f,%.2f)" % isobarycentre(s0, s1, s2)
    f += "{\\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{figure %s}} " % n_fig
    fc = "\\psframe[linestyle=dashed]%s%s\n" % (s0, s2)
    fc += "\\psframe[linestyle=dashed]%s%s\n" % (s2, s1)
    fc += f
    s = "Aire de la figure %s : " % n_fig
    s += u"c'est la moitié de l'aire du rectangle en pointillés.\\par\n"
    s += u"$(%s) \\div 2= %s$~unités d'aire" % (aire_rectangle(dim)[0],
            Affichage.decimaux(aire_rectangle(dim)[1] / 2., 1))
    return f, fc, s
Example #11
0
def tex_somme(exo, cor):
    (ligne1, ligne2) = ([''], ['+'])
    (nba, nbb, deca, decb, lavtvirg, laprvirg) = valeurs()
    total = nba + nbb
    dectotal = [str(total)[i] for i in range(len(str(total)))]
    if dectotal.index('.') <= lavtvirg:
        ligne3 = ['']
    else:
        ligne3 = []
    ligne1 = lignes(ligne1, deca, lavtvirg, laprvirg)
    ligne2 = lignes(ligne2, decb, lavtvirg, laprvirg)
    ligne3 = lignes(ligne3, dectotal, lavtvirg, laprvirg)
    ligne0 = retenues_somme(ligne1, ligne2)
    if ligne0[0] == '1':
        ligne0[0] = '\\tiny 1'
    exo.append('\\item La somme des termes %s et %s.\\par' % (Affichage.decimaux(nba),
             Affichage.decimaux(nbb)))
    cor.append('\\item La somme des termes %s et %s.\\par' % (Affichage.decimaux(nba),
             Affichage.decimaux(nbb)))
    cor.append('\\begin{tabular}[t]{*{%s}{c}}' % (lavtvirg + 
             laprvirg + 1))
    cor.append('%s \\\\' % ' & \\tiny '.join(ligne0))
    cor.append('%s \\\\' % ' & '.join(ligne1))
    cor.append('%s \\\\\n\\hline' % ' & '.join(ligne2))
    cor.append('%s \\\\' % ' & '.join(ligne3))
    cor.append('\\end{tabular}\\par')
    formule = '%s+%s = %s' % (Affichage.decimaux(nba, 1),
                     Affichage.decimaux(nbb, 1), Affichage.decimaux(nba + 
                     nbb, 1))
    cor.append((u'\\[ \\boxed{%s} \\] ').expandtabs(2 * 3) % (formule))
Example #12
0
def tex_produit(exo, cor):
    (nba, nbb, puisa, puisb) = valeurs_prod()
    deca = [','.join(str(nba * 10 ** puisa).rsplit('.'))[i] \
                    for i in range(len(str(nba * 10 ** puisa)))]
    decb = [','.join(str(nbb * 10 ** puisb).rsplit('.'))[i] \
                    for i in range(len(str(nbb * 10 ** puisb)))]

    (dec3, dummy) = pose_mult(nba, nbb)
    (dec3bis, dummy) = pose_mult(nbb, nba)
    total = ((nba * 10 ** puisa) * nbb) * 10 ** puisb
    dec4 = [str(total)[i] for i in range(len(str(total)))]
    if dec4.count('.'):
        i = dec4.index('.')
        if (len(dec4) - i) - 1 < -(puisa + puisb):
            for j in range(-(puisa + puisb) - len(dec4) + i + 1):
                dec4.append('0')  # ajoute les 0 inutiles au produit
        dec4.pop(i)  # supprime le point décimal
        dec4[i - 1] = '%s\\Huge ,' % dec4[i - 1]  # et ajoute une Huge virgule au chiffre des unités
    lg = max(len(dec4), max(len(deca), len(decb)))  # nombre de colonnes dans le tableau
    exo.append('\\item Le produit des facteurs %s et %s.\\par' % (Affichage.decimaux(nba * 
             10 ** puisa), Affichage.decimaux(nbb * 10 ** puisb)))
    cor.append('\\item Le produit des facteurs %s et %s.\\par' % (Affichage.decimaux(nba * 
             10 ** puisa), Affichage.decimaux(nbb * 10 ** puisb)))
    cor.append('\\begin{enumerate}')
    cor.append(u'\\item Première méthode :\\par')
    cor.append('\\begin{tabular}[t]{*{%s}{c}}' % lg)
    cor.append('%s \\\\' % ' & '.join(ligneprod([], deca, lg)))
    cor.append('%s \\\\\n\\hline' % ' & '.join(ligneprod(['$\\times$'], decb, lg)))
    for i in range(len(dec3)):
        dec = [str(dec3[i])[j] for j in range(len(str(dec3[i])))]
        cor.append('%s \\\\' % ' & '.join(ligneprod([], dec, lg)))
    cor.append('\\hline \\\\')
    cor.append('%s \\\\' % ' & '.join(ligneprod([], dec4, lg)))
    cor.append('\\end{tabular}')
    cor.append(u'\\item Seconde méthode :\\par')
    cor.append('\\begin{tabular}[t]{*{%s}{c}}' % len(dec4))
    cor.append('%s \\\\' % ' & '.join(ligneprod([], decb, lg)))
    cor.append('%s \\\\\n\\hline' % ' & '.join(ligneprod(['$\\times$'], deca, lg)))
    for i in range(len(dec3bis)):
        dec = [str(dec3bis[i])[j] for j in range(len(str(dec3bis[i])))]
        cor.append('%s \\\\' % ' & '.join(ligneprod([], dec, lg)))
    cor.append('\\hline \\\\')
    cor.append('%s \\\\' % ' & '.join(ligneprod([], dec4, lg)))
    cor.append('\\end{tabular}')
    cor.append('\\end{enumerate}')

    #===========================================================================
    # # outils.Arithmetique.ecrit_tex(f1, '%s\\times%s = %s' % (Affichage.decimaux(nba *
    #                  # 10 ** puisa, 1), Affichage.decimaux(nbb * 10 **
    #                  # puisb, 1), Affichage.decimaux((nba * nbb) * 10 ** (puisa +
    #                  # puisb), 1)), cadre=1, thenocalcul='', tabs=3)
    #===========================================================================

    #### Remplacement de la fonction Arithmetique.ecrit_tex :

    formule = '%s\\times%s = %s' % (Affichage.decimaux(nba * 
                     10 ** puisa, 1), Affichage.decimaux(nbb * 10 ** 
                     puisb, 1), Affichage.decimaux((nba * nbb) * 10 ** (puisa + 
                     puisb), 1))
    cor.append((u'\\[ \\boxed{%s} \\] ').expandtabs(2 * 3) % (formule))
Example #13
0
def tex_difference(exo, cor):
    (ligne1, ligne2) = ([''], ['-'])
    (nba, nbb, deca, decb, lavtvirg, laprvirg) = valeurs()
    if nba < nbb:
        (nba, nbb, deca, decb) = (nbb, nba, decb, deca)
    total = nba - nbb
    dectotal = [str(total)[i] for i in range(len(str(total)))]
    if dectotal.index('.') <= lavtvirg:
        ligne3 = ['']
    else:
        ligne3 = []
    ligne1 = lignes(ligne1, deca, lavtvirg, laprvirg)
    ligne2 = lignes(ligne2, decb, lavtvirg, laprvirg)
    ligne3 = lignes(ligne3, dectotal, lavtvirg, laprvirg)
    (ligne1, ligne2) = retenues_diff(ligne1, ligne2)
    exo.append(u"\\item La différence des termes %s et %s.\\par" % 
             (Affichage.decimaux(nba), Affichage.decimaux(nbb)))
    cor.append(u"\\item La différence des termes %s et %s.\\par" % 
             (Affichage.decimaux(nba), Affichage.decimaux(nbb)))
    cor.append('\\begin{tabular}[t]{*{%s}{c}}' % (lavtvirg + 
             laprvirg + 1))
    cor.append('%s \\\\' % ' & '.join(ligne1))
    cor.append('%s \\\\\n\\hline' % ' & '.join(ligne2))
    cor.append('%s \\\\' % ' & '.join(ligne3))
    cor.append('\\end{tabular}\\par')
    formule = '%s-%s = %s' % (Affichage.decimaux(nba, 1),
                     Affichage.decimaux(nbb, 1), Affichage.decimaux(nba - 
                     nbb, 1))
    cor.append((u'\\[ \\boxed{%s} \\] ').expandtabs(2 * 3) % (formule))
Example #14
0
def tex_difference(exo, cor):
    (ligne1, ligne2) = ([''], ['-'])
    (nba, nbb, deca, decb, lavtvirg, laprvirg) = valeurs()
    if nba < nbb:
        (nba, nbb, deca, decb) = (nbb, nba, decb, deca)
    total = nba - nbb
    dectotal = [str(total)[i] for i in range(len(str(total)))]
    if dectotal.index('.') <= lavtvirg:
        ligne3 = ['']
    else:
        ligne3 = []
    ligne1 = lignes(ligne1, deca, lavtvirg, laprvirg)
    ligne2 = lignes(ligne2, decb, lavtvirg, laprvirg)
    ligne3 = lignes(ligne3, dectotal, lavtvirg, laprvirg)
    (ligne1, ligne2) = retenues_diff(ligne1, ligne2)
    exo.append(u"\\item La différence des termes %s et %s.\\par" %
               (Affichage.decimaux(nba), Affichage.decimaux(nbb)))
    cor.append(u"\\item La différence des termes %s et %s.\\par" %
               (Affichage.decimaux(nba), Affichage.decimaux(nbb)))
    cor.append('\\begin{tabular}[t]{*{%s}{c}}' % (lavtvirg + laprvirg + 1))
    cor.append('%s \\\\' % ' & '.join(ligne1))
    cor.append('%s \\\\\n\\hline' % ' & '.join(ligne2))
    cor.append('%s \\\\' % ' & '.join(ligne3))
    cor.append('\\end{tabular}\\par')
    formule = '%s-%s = %s' % (Affichage.decimaux(
        nba, 1), Affichage.decimaux(nbb, 1), Affichage.decimaux(nba - nbb, 1))
    cor.append((u'\\[ \\boxed{%s} \\] ').expandtabs(2 * 3) % (formule))
Example #15
0
def tex_somme(exo, cor):
    (ligne1, ligne2) = ([''], ['+'])
    (nba, nbb, deca, decb, lavtvirg, laprvirg) = valeurs()
    total = nba + nbb
    dectotal = [str(total)[i] for i in range(len(str(total)))]
    if dectotal.index('.') <= lavtvirg:
        ligne3 = ['']
    else:
        ligne3 = []
    ligne1 = lignes(ligne1, deca, lavtvirg, laprvirg)
    ligne2 = lignes(ligne2, decb, lavtvirg, laprvirg)
    ligne3 = lignes(ligne3, dectotal, lavtvirg, laprvirg)
    ligne0 = retenues_somme(ligne1, ligne2)
    if ligne0[0] == '1':
        ligne0[0] = '\\tiny 1'
    exo.append('\\item La somme des termes %s et %s.\\par' %
               (Affichage.decimaux(nba), Affichage.decimaux(nbb)))
    cor.append('\\item La somme des termes %s et %s.\\par' %
               (Affichage.decimaux(nba), Affichage.decimaux(nbb)))
    cor.append('\\begin{tabular}[t]{*{%s}{c}}' % (lavtvirg + laprvirg + 1))
    cor.append('%s \\\\' % ' & \\tiny '.join(ligne0))
    cor.append('%s \\\\' % ' & '.join(ligne1))
    cor.append('%s \\\\\n\\hline' % ' & '.join(ligne2))
    cor.append('%s \\\\' % ' & '.join(ligne3))
    cor.append('\\end{tabular}\\par')
    formule = '%s+%s = %s' % (Affichage.decimaux(
        nba, 1), Affichage.decimaux(nbb, 1), Affichage.decimaux(nba + nbb, 1))
    cor.append((u'\\[ \\boxed{%s} \\] ').expandtabs(2 * 3) % (formule))
Example #16
0
def tex_decomposition(v, p):
    exo, cor = [], []
    for i in range(3):
        if p[i] < 0:
            exo.append('%s\\times \\cfrac{1}{%s}' %
                       (v[i], Affichage.decimaux(10**(-p[i]), 1)))
            cor.append('%s\\times \\cfrac{1}{%s}' %
                       (v[i], Affichage.decimaux(10**(-p[i]), 1)))
        else:
            exo.append('%s\\times %s' %
                       (v[i], Affichage.decimaux(10**p[i], 1)))
            cor.append('%s\\times %s' %
                       (v[i], Affichage.decimaux(10**p[i], 1)))
        if i < 2:
            exo.append('+')
            cor.append('+')
        else:
            exo.append('=')
            cor.append('=')
    exo.append('\\dotfill$')
    cor.append('%s$' % Affichage.decimaux(
        v[0] * 10**p[0] + v[1] * 10**p[1] + v[2] * 10**p[2], 1))
    return " ".join(exo), " ".join(cor)
Example #17
0
def tex_decomposition(v, p):
    exo, cor = [], []
    for i in range(3):
        if p[i] < 0:
            exo.append('%s\\times \\cfrac{1}{%s}' % (v[i],
                Affichage.decimaux(10 ** (-p[i]), 1)))
            cor.append('%s\\times \\cfrac{1}{%s}' % (v[i],
                Affichage.decimaux(10 ** (-p[i]), 1)))
        else:
            exo.append('%s\\times %s' % (v[i], Affichage.decimaux(10 ** 
                     p[i], 1)))
            cor.append('%s\\times %s' % (v[i], Affichage.decimaux(10 ** 
                     p[i], 1)))
        if i < 2:
            exo.append('+')
            cor.append('+')
        else:
            exo.append('=')
            cor.append('=')
    exo.append('\\dotfill$')
    cor.append('%s$' % Affichage.decimaux(v[0] * 10 ** p[0] + 
             v[1] * 10 ** p[1] + v[2] * 10 ** p[2], 1))
    return " ".join(exo), " ".join(cor)
Example #18
0
def triangle_rectangle(dim, n_fig):
    """Dessine en psTricks un triangle rectangle dans une boite de dimensions
    dim et numérote la figure avec n_fig"""
    sommets = [(0, 0), (dim[0], 0), dim, (0, dim[1])]
    s0 = random.randrange(4)
    s1, s2 = (s0 + 1) % 4, (s0 + 2) % 4
    s0, s1, s2 = sommets[s0], sommets[s1], sommets[s2]
    f = "\\pspolygon[fillstyle=hlines]%s%s%s\n" % (s0, s1,
            s2)
    f += "\\rput(%.2f,%.2f)" % isobarycentre(s0, s1, s2)
    f += "{\\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{figure %s}} " % n_fig
    fc = "\\psframe[linestyle=dashed]%s%s\n" % (s0, s2)
    fc += f
    s = "Aire de la figure %s : " % n_fig
    s += u"c'est la moitié de l'aire du rectangle en pointillés.\\par\n"
    s += u"$(%s) \\div 2= %s$~unités d'aire" % (aire_rectangle(dim)[0],
            Affichage.decimaux(aire_rectangle(dim)[1] / 2., 1))
    return f, fc, s
Example #19
0
def triangle_qcq(dim, n_fig):
    """Dessine en psTricks un triangle quelconque dans une boite de dimensions
    dim et numérote la figure avec n_fig"""
    sommets = [(0, 0), (dim[0], 0), dim, (0, dim[1])]
    s0 = random.randrange(4)
    angle0, angle1, angle2 = sommets[(s0 + 1) % 4], sommets[(s0 + 2) % 4], sommets[(s0 + 3) % 4]
    x0, x1 = sommets[(s0 + 1) % 4][0], sommets[(s0 + 2) % 4][0]
    y0, y1 = sommets[(s0 + 1) % 4][1], sommets[(s0 + 2) % 4][1]
    if x0 > x1: x0, x1 = x1, x0
    if y0 > y1: y0, y1 = y1, y0
    if x0 != x1: x0 = random.randrange(x0 + 1, x1)
    if y0 != y1: y0 = random.randrange(y0 + 1, y1)
    s1 = (x0, y0)
    x0, x1 = sommets[(s0 + 2) % 4][0], sommets[(s0 + 3) % 4][0]
    y0, y1 = sommets[(s0 + 2) % 4][1], sommets[(s0 + 3) % 4][1]
    if x0 > x1: x0, x1 = x1, x0
    if y0 > y1: y0, y1 = y1, y0
    if x0 != x1: x0 = random.randrange(x0 + 1, x1)
    if y0 != y1: y0 = random.randrange(y0 + 1, y1)
    s2 = (x0, y0)
    s0 = sommets[s0]
    f = "\\pspolygon[fillstyle=hlines]%s%s%s\n" % (s0, s1,
            s2)
    f += "\\rput(%.2f,%.2f)" % isobarycentre(s0, s1, s2)
    f += "{\\psframebox[linecolor=white, fillcolor=white, fillstyle=solid]{figure %s}}" % n_fig
    fc = "\\psframe[linestyle=dashed](0,0)(%s,%s) " % dim
    fc += "\\rput(%.2f,%.2f){\\pscirclebox{1}} " % isobarycentre(s0, s1, angle0)
    fc += "\\rput(%.2f,%.2f){\\pscirclebox{2}} " % isobarycentre(s1, s2, angle1)
    fc += "\\rput(%.2f,%.2f){\\pscirclebox{3}}\n" % isobarycentre(s2, s0, angle2)
    fc += f
    s = "Aire de la figure %s : " % n_fig
    s += u"on calcule l'aire du rectangle en pointillés et on soustrait "
    s += "les aires des triangles rectangles \\pscirclebox{1}, "
    s += "\\pscirclebox{2} et \\pscirclebox{3}.\\par\n"
    s += "$(%s) - (%s) \\div 2 - (%s) \\div 2 - (%s) \\div 2 " % \
            (aire_rectangle(dim)[0], aire_rectangle(s0, s1)[0],
                    aire_rectangle(s1, s2)[0], aire_rectangle(s2, s0)[0])
    s += u"= %s$~unités d'aire" % Affichage.decimaux(aire_rectangle(dim)[1] - 
            aire_rectangle(s0, s1)[1] / 2. - aire_rectangle(s0, s2)[1] / 2. - 
            aire_rectangle(s1, s2)[1] / 2., 1)
    return f, fc, s
Example #20
0
def tex_formule_dix(l, exo, cor):
    if l[2] == '*':
        alea = random.randrange(0, 5)
        if alea > 1:
            exo.append(
                '\\item $%s \\quad\\times\\quad %s \\quad = \\quad \\dotfill$'
                % (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[1], 1)))
            cor.append('\\item $%s \\times %s = \\mathbf{%s}$' %
                       (Affichage.decimaux(l[0], 1), Affichage.decimaux(
                           l[1], 1), Affichage.decimaux(l[0] * l[1], 1)))
        elif alea > 0:
            exo.append(
                '\\item $%s \\quad\\times\\quad \\dotfill \\quad = \\quad %s$'
                % (Affichage.decimaux(l[0],
                                      1), Affichage.decimaux(l[0] * l[1], 1)))
            cor.append('\\item $%s \\times \\mathbf{%s} = %s$' %
                       (Affichage.decimaux(l[0], 1), Affichage.decimaux(
                           l[1], 1), Affichage.decimaux(l[0] * l[1], 1)))
        else:
            exo.append(
                '\\item $\\dotfill \\quad\\times\\quad %s \\quad = \\quad %s$'
                % (Affichage.decimaux(l[1],
                                      1), Affichage.decimaux(l[0] * l[1], 1)))
            cor.append('\\item $\\mathbf{%s} \\times %s = %s$' %
                       (Affichage.decimaux(l[0], 1), Affichage.decimaux(
                           l[1], 1), Affichage.decimaux(l[0] * l[1], 1)))
    else:
        alea = random.randrange(0, 5)
        if alea > 1:
            exo.append(
                '\\item $%s \\quad\\div\\quad %s \\quad = \\quad \\dotfill$' %
                (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[1], 1)))
            cor.append('\\item $%s \\div %s = \\mathbf{%s}$' %
                       (Affichage.decimaux(l[0], 1), Affichage.decimaux(
                           l[1], 1), Affichage.decimaux(l[0] / l[1], 1)))
        elif alea > 0:
            exo.append(
                '\\item $%s \\quad\\div\\quad \\dotfill \\quad = \\quad %s$' %
                (Affichage.decimaux(l[0], 1), Affichage.decimaux(
                    l[0] / l[1], 1)))
            cor.append('\\item $%s \\div \\mathbf{%s} = %s$' %
                       (Affichage.decimaux(l[0], 1), Affichage.decimaux(
                           l[1], 1), Affichage.decimaux(l[0] / l[1], 1)))
        else:
            exo.append(
                '\\item $\\dotfill \\quad\\div\\quad %s \\quad = \\quad %s$' %
                (Affichage.decimaux(l[1], 1), Affichage.decimaux(
                    l[0] / l[1], 1)))
            cor.append('\\item $\\mathbf{%s} \\div %s = %s$' %
                       (Affichage.decimaux(l[0], 1), Affichage.decimaux(
                           l[1], 1), Affichage.decimaux(l[0] / l[1], 1)))
Example #21
0
def tex_produit(exo, cor):
    (nba, nbb, puisa, puisb) = valeurs_prod()
    deca = [','.join(str(nba * 10 ** puisa).rsplit('.'))[i] \
                    for i in range(len(str(nba * 10 ** puisa)))]
    decb = [','.join(str(nbb * 10 ** puisb).rsplit('.'))[i] \
                    for i in range(len(str(nbb * 10 ** puisb)))]

    (dec3, dummy) = pose_mult(nba, nbb)
    (dec3bis, dummy) = pose_mult(nbb, nba)
    total = ((nba * 10**puisa) * nbb) * 10**puisb
    dec4 = [str(total)[i] for i in range(len(str(total)))]
    if dec4.count('.'):
        i = dec4.index('.')
        if (len(dec4) - i) - 1 < -(puisa + puisb):
            for j in range(-(puisa + puisb) - len(dec4) + i + 1):
                dec4.append('0')  # ajoute les 0 inutiles au produit
        dec4.pop(i)  # supprime le point décimal
        dec4[i - 1] = '%s\\Huge ,' % dec4[
            i - 1]  # et ajoute une Huge virgule au chiffre des unités
    lg = max(len(dec4), max(len(deca),
                            len(decb)))  # nombre de colonnes dans le tableau
    exo.append('\\item Le produit des facteurs %s et %s.\\par' %
               (Affichage.decimaux(
                   nba * 10**puisa), Affichage.decimaux(nbb * 10**puisb)))
    cor.append('\\item Le produit des facteurs %s et %s.\\par' %
               (Affichage.decimaux(
                   nba * 10**puisa), Affichage.decimaux(nbb * 10**puisb)))
    cor.append('\\begin{enumerate}')
    cor.append(u'\\item Première méthode :\\par')
    lg = max(len(dec4), max(len(deca), len(decb) + 1))
    cor.append('\\begin{tabular}[t]{*{%s}{c}}' % lg)
    cor.append('%s \\\\' % ' & '.join(ligneprod([], deca, lg)))
    cor.append('%s \\\\\n\\hline' %
               ' & '.join(ligneprod(['$\\times$'], decb, lg)))
    for i in range(len(dec3)):
        dec = [str(dec3[i])[j] for j in range(len(str(dec3[i])))]
        cor.append('%s \\\\' % ' & '.join(ligneprod([], dec, lg)))
    cor.append('\\hline \\\\')
    cor.append('%s \\\\' % ' & '.join(ligneprod([], dec4, lg)))
    cor.append('\\end{tabular}')
    cor.append(u'\\item Seconde méthode :\\par')
    lg = max(len(dec4), max(len(deca) + 1, len(decb)))
    cor.append('\\begin{tabular}[t]{*{%s}{c}}' % lg)
    cor.append('%s \\\\' % ' & '.join(ligneprod([], decb, lg)))
    cor.append('%s \\\\\n\\hline' %
               ' & '.join(ligneprod(['$\\times$'], deca, lg)))
    for i in range(len(dec3bis)):
        dec = [str(dec3bis[i])[j] for j in range(len(str(dec3bis[i])))]
        cor.append('%s \\\\' % ' & '.join(ligneprod([], dec, lg)))
    cor.append('\\hline \\\\')
    cor.append('%s \\\\' % ' & '.join(ligneprod([], dec4, lg)))
    cor.append('\\end{tabular}')
    cor.append('\\end{enumerate}')

    #===========================================================================
    # # outils.Arithmetique.ecrit_tex(f1, '%s\\times%s = %s' % (Affichage.decimaux(nba *
    #                  # 10 ** puisa, 1), Affichage.decimaux(nbb * 10 **
    #                  # puisb, 1), Affichage.decimaux((nba * nbb) * 10 ** (puisa +
    #                  # puisb), 1)), cadre=1, thenocalcul='', tabs=3)
    #===========================================================================

    #### Remplacement de la fonction Arithmetique.ecrit_tex :

    formule = '%s\\times%s = %s' % (Affichage.decimaux(
        nba * 10**puisa, 1), Affichage.decimaux(nbb * 10**puisb, 1),
                                    Affichage.decimaux(
                                        (nba * nbb) * 10**(puisa + puisb), 1))
    cor.append((u'\\[ \\boxed{%s} \\] ').expandtabs(2 * 3) % (formule))
Example #22
0
def choix_trou_frac(exo, cor, n1, p1):
    i = random.randrange(3)
    p2 = random.randrange(2)  # sert à compliquer un peu l'exercice
    if i > 1:
        exo.append('\\item $\\cfrac{%s}{%s}=\\ldots$' % 
                (Affichage.decimaux(n1 * 10 ** p2),
                    Affichage.decimaux(10 ** (p1 + p2))))
        cor.append('\\item $\\cfrac{%s}{%s}=\\mathbf{%s}$' % 
                (Affichage.decimaux(n1 * 10 ** p2),
                    Affichage.decimaux(10 ** (p1 + p2)),
                    Affichage.decimaux(n1 * 10 ** (-p1), 1)))
    elif i > 0:
        exo.append('\\item $\\cfrac{%s}{\ldots}=%s$' % 
                (Affichage.decimaux(n1 * 10 ** p2),
        Affichage.decimaux(n1 * 10 ** (-p1), 1)))
        cor.append('\\item $\\cfrac{%s}{\\mathbf{%s}}=%s$' % 
                (Affichage.decimaux(n1 * 10 ** p2),
        Affichage.decimaux(10 ** (p1 + p2)), \
                Affichage.decimaux(n1 * 10 ** (-p1), 1)))
    else:
        exo.append('\\item $\\cfrac{\ldots}{%s}=%s$' % 
                (Affichage.decimaux(10 ** (p1 + p2)),
        Affichage.decimaux(n1 * 10 ** (-p1), 1)))
        cor.append('\\item $\\cfrac{\\mathbf{%s}}{%s}=%s$' % 
                (Affichage.decimaux(n1 * 10 ** p2),
                    Affichage.decimaux(10 ** (p1 + p2)),
                    Affichage.decimaux(n1 * 10 ** (-p1), 1)))
Example #23
0
def EcritEnLettre(exo, cor):
    lnb = nombreATrouver()
    for i in range(8):
        exo.append("\\item " + Affichage.decimaux(lnb[i], 0) + " : \\dotfill")
        cor.append("\\item " + Affichage.decimaux(lnb[i], 0) + " : ")
        cor.append(EcritNombreDecimal(lnb[i]) + '')
Example #24
0
def choix_trou_frac(exo, cor, n1, p1):
    i = random.randrange(3)
    p2 = random.randrange(2)  # sert à compliquer un peu l'exercice
    if i > 1:
        exo.append('\\item $\\cfrac{%s}{%s}=\\ldots$' % (Affichage.decimaux(
            n1 * 10**p2), Affichage.decimaux(10**(p1 + p2))))
        cor.append(
            '\\item $\\cfrac{%s}{%s}=\\mathbf{%s}$' %
            (Affichage.decimaux(n1 * 10**p2), Affichage.decimaux(
                10**(p1 + p2)), Affichage.decimaux(n1 * 10**(-p1), 1)))
    elif i > 0:
        exo.append('\\item $\\cfrac{%s}{\ldots}=%s$' % (Affichage.decimaux(
            n1 * 10**p2), Affichage.decimaux(n1 * 10**(-p1), 1)))
        cor.append('\\item $\\cfrac{%s}{\\mathbf{%s}}=%s$' %
                (Affichage.decimaux(n1 * 10 ** p2),
        Affichage.decimaux(10 ** (p1 + p2)), \
                Affichage.decimaux(n1 * 10 ** (-p1), 1)))
    else:
        exo.append('\\item $\\cfrac{\ldots}{%s}=%s$' % (Affichage.decimaux(
            10**(p1 + p2)), Affichage.decimaux(n1 * 10**(-p1), 1)))
        cor.append(
            '\\item $\\cfrac{\\mathbf{%s}}{%s}=%s$' %
            (Affichage.decimaux(n1 * 10**p2), Affichage.decimaux(
                10**(p1 + p2)), Affichage.decimaux(n1 * 10**(-p1), 1)))
Example #25
0
def tex_formule_dix(l, exo, cor):
    if l[2] == '*':
        alea = random.randrange(0, 5)
        if alea > 1:
            exo.append('\\item $%s \\quad\\times\\quad %s \\quad = \\quad \\dotfill$' % 
                     (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[1],
                     1)))
            cor.append('\\item $%s \\times %s = \\mathbf{%s}$' % 
                     (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[1],
                     1), Affichage.decimaux(l[0] * l[1], 1)))
        elif alea > 0:
            exo.append('\\item $%s \\quad\\times\\quad \\dotfill \\quad = \\quad %s$' % 
                     (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[0] * 
                     l[1], 1)))
            cor.append('\\item $%s \\times \\mathbf{%s} = %s$' % 
                     (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[1],
                     1), Affichage.decimaux(l[0] * l[1], 1)))
        else:
            exo.append('\\item $\\dotfill \\quad\\times\\quad %s \\quad = \\quad %s$' % 
                     (Affichage.decimaux(l[1], 1), Affichage.decimaux(l[0] * 
                     l[1], 1)))
            cor.append('\\item $\\mathbf{%s} \\times %s = %s$' % 
                     (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[1],
                     1), Affichage.decimaux(l[0] * l[1], 1)))
    else:
        alea = random.randrange(0, 5)
        if alea > 1:
            exo.append('\\item $%s \\quad\\div\\quad %s \\quad = \\quad \\dotfill$' % 
                     (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[1],
                     1)))
            cor.append('\\item $%s \\div %s = \\mathbf{%s}$' % (Affichage.decimaux(l[0],
                     1), Affichage.decimaux(l[1], 1), Affichage.decimaux(l[0] / 
                     l[1], 1)))
        elif alea > 0:
            exo.append('\\item $%s \\quad\\div\\quad \\dotfill \\quad = \\quad %s$' % 
                     (Affichage.decimaux(l[0], 1), Affichage.decimaux(l[0] / 
                     l[1], 1)))
            cor.append('\\item $%s \\div \\mathbf{%s} = %s$' % (Affichage.decimaux(l[0],
                     1), Affichage.decimaux(l[1], 1), Affichage.decimaux(l[0] / 
                     l[1], 1)))
        else:
            exo.append('\\item $\\dotfill \\quad\\div\\quad %s \\quad = \\quad %s$' % 
                     (Affichage.decimaux(l[1], 1), Affichage.decimaux(l[0] / 
                     l[1], 1)))
            cor.append('\\item $\\mathbf{%s} \\div %s = %s$' % (Affichage.decimaux(l[0],
                     1), Affichage.decimaux(l[1], 1), Affichage.decimaux(l[0] / 
                     l[1], 1)))