コード例 #1
0
def getMultiplication(min=1, max=9, pDiv=0.5, pNeg=.5, fraction=False):
    """
    Retourne un calcul de multiplication de fraction
    - min : valeur minimum
    """
    a = randomValue(min, max, pNeg=pNeg)
    b = randomValue(min, max, pNeg=pNeg)
    c = randomValue(min, max, pNeg=pNeg)
    d = randomValue(min, max, pNeg=pNeg)
    while d == 1 and b == 1:  # ajout de deux entiers : inutile
        d = randomValue(min, max, pNeg=pNeg)

    if b == 1:
        frac1 = str(a)
    else:
        frac1 = "\\dfrac{" + str(a) + "}{" + str(b) + "}"

    if d == 1:
        frac2 = str(c)
    else:
        frac2 = "\\dfrac{" + str(c) + "}{" + str(d) + "}"

    op = "\\times" if random() > pDiv else "\\div"
    if fraction and op == "\\div":
        return "\\dfrac{" + frac1 + "}{" + frac2 + "}"
    else:
        return frac1 + op + frac2
コード例 #2
0
def getProduitAffine(nbDigit=0,
                     equation=True,
                     possibleLetter="x",
                     simple=False):
    a = randomValue(1, 9, nbDigit)
    b = randomValue(1, 9, nbDigit)
    c = randomValue(1, 9, nbDigit)
    d = randomValue(1, 9, nbDigit)

    letter = choice(possibleLetter)

    op1 = choice(["+", "-"])
    neg1 = choice(["-", ""])
    op2 = choice(["+", "-"])
    neg2 = choice(["-", ""])

    if simple:
        a = 1
        c = 1
        neg1 = ""
        neg2 = ""

    if equation:
        eq = "="
    else:
        eq = choice(["<", ">", "\geq", "\leq"])

    if a == 1:
        a = ""
    if c == 1:
        c = ""
    return f"$({neg1}{a}{letter} {op1} {b}) ({neg2}{c}{letter} {op2} {d}){eq} 0$"
コード例 #3
0
def getAddition(min=1, max=9, pSub=0.5, pNeg=.5):
    a = randomValue(min, max)
    b = randomValue(min, max)
    c = randomValue(min, max)
    d = randomValue(min, max)
    while d == 1 and b == 1:  # ajout de deux entiers : inutile
        d = randomValue(min, max)

    if random() < pNeg: a = -a
    if random() < pNeg: b = -b
    if random() < pNeg: c = -c
    if random() < pNeg: d = -d

    if b == 1:
        frac1 = str(a)
    else:
        frac1 = "\\dfrac{" + str(a) + "}{" + str(b) + "}"

    if d == 1:
        frac2 = str(c)
    else:
        frac2 = "\\dfrac{" + str(c) + "}{" + str(d) + "}"

    op = "+" if random() > pSub else "-"

    return frac1 + op + frac2
コード例 #4
0
def getSquare(nbDigit=0, possibleLetter="x"):
    a = randomValue(1, 9, nbDigit)
    b = randomValue(1, 9, nbDigit)

    letter = choice(possibleLetter)

    eq = "="

    if a == 1:
        a = ""
    return f"${a}{letter}^2 {eq} {round((b**2)*a, nbDigit * 2)}$"
コード例 #5
0
def getAbsoluteIneq(nbDigit=0, p=0.2):
    v = randomValue(1, 9, nbDigit)
    r = randomValue(1, 9, nbDigit)

    op = choice(["+", "-"])
    ineq = choice(["<", ">", "\leq", "\geq"])

    result = ""
    if (random() < p):  #forme |a=x|=b
        result += "$|" + str(v) + op + "x|"
    else:  #forme |a=x|=b
        result += "$|x" + op + str(v) + "|"
    result += ineq + str(r) + "\hspace{1cm} x \in ..................$"
    return result
コード例 #6
0
def getAbsoluteEq(nbDigit=0, p=0.2):

    v = randomValue(1, 9, nbDigit)
    r = randomValue(1, 9, nbDigit)

    op = choice(["+", "-"])

    if (random() < p):  #forme |a=x|=b
        result = "$|" + str(v) + op + "x| = " + str(
            r) + "\hspace{1cm} x = ......... $ ou $x = .........$"
    else:  #forme |a=x|=b
        result = "$|x" + op + str(v) + "| = " + str(
            r) + "\hspace{1cm} x = ......... $ ou $x = .........$"

    return result
コード例 #7
0
def getSquareAffine(nbDigit=0, possibleLetter="x"):
    a = randomValue(1, 9, nbDigit)
    b = randomValue(1, 9, nbDigit)
    c = randomValue(1, 9, nbDigit)

    letter = choice(possibleLetter)

    eq = "="

    op = choice(["+", "-"])
    neg = choice(["-", ""])

    if a == 1:
        a = ""
    return f"$({neg}{a}{letter} {op} {b})^2{eq} {round(c**2, nbDigit * 2)}$"
コード例 #8
0
def getAffine(nbDigit=0, equation=True, possibleLetter="x"):
    a = randomValue(1, 9, nbDigit)
    b = randomValue(1, 9, nbDigit)
    c = randomValue(1, 9, nbDigit)

    letter = choice(possibleLetter)
    if equation:
        eq = "="
    else:
        eq = choice(["<", ">", "\geq", "\leq"])
    op = choice(["+", "-"])
    neg = choice(["-", ""])

    if a == 1:
        a = ""
    return f"${neg}{a}{letter} {op} {b} {eq} {c}$"
コード例 #9
0
ファイル: exDroite.py プロジェクト: gplantard/GeneraTex
def getLectureAffine(nbDroite = 1 , labelSize = LatexFontSize.large):
    result = ""
    graph = Graphique()
    graph.repere = Repere(xUnitVect = (1,0), yUnitVect = (0,1))

    graph.addPoint(1,2, "B")

    for i in range(nbDroite):
        a = randomValue(-5, 5)
        b = randomValue(1, 5)
        if random.random() > .5:
            b = -b
        c = randomValue(graph.repere.ymin, graph.repere.ymax)
        graph.addAffine(a/b,c)

    #graph.addAffine(-1/4,-2, nom="test")

    return graph.render(labelSize)
コード例 #10
0
def convertTemplate(template, min=1, max=9, pNeg=.5):
    result = ""
    for c in template:
        if c == "f":
            a = randomValue(min, max, pNeg=pNeg)
            b = randomValue(min, max, pNeg=pNeg)
            result += "(" + str(a) + "/" + str(b) + ")"
        elif c == "e":
            a = randomValue(min, max, pNeg=pNeg)
            result += f"{a}"
        elif c == "p":
            a = randomValue(min, max, pNeg=0)
            result += f"{a}"
        elif c == "n":
            a = randomValue(min, max, pNeg=1)
            result += f"{a}"
        else:
            result += c
    calcul = Calcul.fromExpression(result)
    return calcul.toLatex()
コード例 #11
0
def getDoubleAffine(nbDigit=0, equation=True, possibleLetter="x"):
    a = randomValue(1, 9, nbDigit)
    b = randomValue(1, 9, nbDigit)
    c = randomValue(1, 9, nbDigit)
    d = randomValue(1, 9, nbDigit)

    letter = choice(possibleLetter)

    op1 = choice(["+", "-"])
    neg1 = choice(["-", ""])
    op2 = choice(["+", "-"])
    neg2 = choice(["-", ""])

    if equation:
        eq = "="
    else:
        eq = choice(["<", ">", "\geq", "\leq"])

    if a == 1:
        a = ""
    if c == 1:
        c = ""
    return f"${neg1}{a}{letter} {op1} {b} {eq} {neg2}{c}{letter} {op2} {d}$"