-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculatrice.py
More file actions
39 lines (35 loc) · 1.19 KB
/
calculatrice.py
File metadata and controls
39 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sys
def main():
nombre1 = input("Nombre #1 : ")
nombre2 = input("Nombre #2 : ")
operation = input("Entrez l'operation +, -, * ou / : ")
resultat = 0
if not nombre1.isnumeric() or not nombre2.isnumeric() :
print("Erreur: Les deux valeurs doivent être des nombres entiers")
sys.exit()
else :
nombre1 = int(nombre1)
nombre2 = int(nombre2)
match operation:
case "+":
resultat = nombre1 + nombre2
print(f"Le résultat est {resultat}")
case "-":
resultat = nombre1 - nombre2
print(f"Le résultat est {resultat}")
case "*":
resultat = nombre1 * nombre2
print(f"Le résultat est {resultat}")
case "/":
if nombre2 == 0:
print("Division par 0 impossible !")
sys.exit()
else:
resultat = nombre1 / nombre2
print(f"Le résultat est {resultat}")
case _:
print("Erreur: Vous devez entrer +, -, * ou / pour l'opération")
sys.exit()
# Ne touchez pas le code ci-dessous
if __name__ == "__main__":
main()