Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SalahMaroc authored Apr 13, 2024
1 parent 91c0a4d commit 6bf4539
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions P2/P2C1/énoncé/main.py
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()

0 comments on commit 6bf4539

Please sign in to comment.