Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1)Algorithme
Algorithme Afficher_Table_Verite_et_Formes_Canoniques(fonction_logique)
Fonction Evaluer_Fonction(expression, valeurs):
// Évalue une expression logique pour un ensemble donné de valeurs booléennes
// Retourne le résultat de l'évaluation de l'expression
// Implémentation de la logique d'évaluation de l'expression
...
Fin Algorithme
2)Python
from itertools import product
def evaluate_function(expression, inputs):
"""
Évalue une expression logique donnée pour un ensemble d'entrées.
"""
values = {chr(97 + i): inputs[i] for i in range(len(inputs))}
return eval(expression, values)
def truth_table(expression):
"""
Génère la table de vérité pour une expression logique donnée.
"""
variables = sorted(set([char for char in expression if char.isalpha()]))
header = " | ".join(variables + [expression])
separator = "-" * len(header)
print(header)
print(separator)
for inputs in product([0, 1], repeat=len(variables)):
outputs = evaluate_function(expression, inputs)
row = " | ".join(map(str, inputs + (outputs,)))
print(row)
def first_canonical_form(expression):
"""
Génère la première forme canonique pour une expression logique donnée.
"""
terms = []
variables = sorted(set([char for char in expression if char.isalpha()]))
for inputs in product([0, 1], repeat=len(variables)):
outputs = evaluate_function(expression, inputs)
if outputs:
term = ""
for i, value in enumerate(inputs):
if value == 0:
term += f"~{variables[i]} & "
else:
term += f"{variables[i]} & "
term = term[:-2] # Supprimer le dernier "&"
terms.append(term)
return " | ".join(terms)
def second_canonical_form(expression):
"""
Génère la seconde forme canonique pour une expression logique donnée.
"""
variables = sorted(set([char for char in expression if char.isalpha()]))
terms = []
for inputs in product([0, 1], repeat=len(variables)):
outputs = evaluate_function(expression, inputs)
if not outputs:
term = ""
for i, value in enumerate(inputs):
if value == 0:
term += f"{variables[i]} | "
else:
term += f"~{variables[i]} | "
term = term[:-2] # Supprimer le dernier "|"
terms.append(term)
return " & ".join(terms)
def main():
expression = input("Entrez l'expression logique (utilisez 'and', 'or', 'not', '(', ')'): ")
if name == "main":
main()
Why:
Closes:
What's being changed (if available, include any code snippets, screenshots, or gifs):
Check off the following:
I have reviewed my changes in staging, available via the View deployment link in this PR's timeline (this link will be available after opening the PR).
datadirectory.For content changes, I have completed the self-review checklist.