-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91c0a4d
commit 6bf4539
Showing
1 changed file
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
def main(): | ||
# Ecrivez votre code ici ! | ||
# Attention tout votre code doit être indenté comme ce commentaire | ||
nombre_a_gauche = input("Entrez un nombre entier : ") | ||
nombre_a_droite = input("Entrez un nombre entier : ") | ||
operation = input("Entrez l'opération souhaitée ['+', '-', '*' ou '/'] : ") | ||
|
||
resultat = 0 | ||
|
||
# Pour vérifie si les deux nombres sont valides avec la fonction | ||
# soit un integer, ou un float | ||
if not nombre_a_gauche.isnumeric() or not nombre_a_droite.isnumeric(): | ||
print("Erreur: les deux nombres doivent être des nombres entiers") | ||
else: | ||
nombre_a_gauche = int(nombre_a_gauche) | ||
nombre_a_droite = int(nombre_a_droite) | ||
|
||
match operation: | ||
case "+": | ||
resultat = nombre_a_gauche + nombre_a_droite | ||
case "-": | ||
resultat = nombre_a_gauche - nombre_a_droite | ||
case "*": | ||
resultat = nombre_a_gauche * nombre_a_droite | ||
case "/": | ||
# Pour Vérifier si variable `nombre_a_droite` n'est pas nulle pour la division | ||
if nombre_a_droite == 0: | ||
print("Erreur: impossible de diviser par zéro.") | ||
else: | ||
resultat = nombre_a_gauche / nombre_a_droite | ||
# Si le symbole est incorrect. | ||
case _: | ||
print("Erreur: le symbole d'opération doit être '+', '-', '*' ou '/'.") | ||
|
||
# Affiche le résultat | ||
print(f"Le résultat de l'opération est: {resultat}") | ||
|
||
# Ne touchez pas le code ci-dessous | ||
if __name__ == "__main__": | ||
main() | ||
main() |