.............................
def translate(s):
    """Usage: translate('P and not Q') -> 'P \wedge \neg Q'"""
    return s.replace("not", r"\neg").replace("and", r"\wedge").replace("or", r"\vee")
    
def verite(s):
    """Usage: verite('P and not Q') -> 'FVFF'"""
    tab = ""
    for P in (True, False):
        for Q in (True, False):
           tab += ("V" if eval(s) else "F")
    return tab    
    
def table(prop, verite):
    """Usage: table('P and Q', 'VFVV') -> latex tabular"""
    t = [r"\begin{tabular}{|c|c|c|}\hline $P$&$Q$&$%s$\\\hline" % translate(prop)]
    i = 0
    for P in "VF":
        for Q in "VF":
            t.append(fr"{P}&{Q}&{verite[i]}\\")
            i += 1
    t.append(r"\hline\end{tabular}")
    return "\n".join(t)

prop = randchoice(["not P or Q", "P or not Q", "not P and Q", "P and not Q"])
liste = [table(prop, val) for val in ("VVFF", "VFVF", "VFVV", "VVFV", "FFVF", "FVFF", "FVVV", "FVVF", "FVFV")]
shuffle(liste)

tableau_correct = table(prop, verite(prop))
.............................
Quelle est la table de vérité de $#{translate(prop)}$~?

#ANSWERS_LIST{liste}{tableau_correct,}



