-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcepcionesI.py
More file actions
92 lines (55 loc) · 1.79 KB
/
ExcepcionesI.py
File metadata and controls
92 lines (55 loc) · 1.79 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
def sumar(num1, num2):
return num1 + num2
def restar(num1, num2):
return num1 - num2
def multiplicar(num1, num2):
return num1 * num2
def dividir(num1, num2):
try:
return num1 / num2
except:
print(" No se puede dividir entre cero")
return "Operación Errónea"
def menu():
print("\n\t\t OPERACIONES \n")
print(" Elija una de las siguientes operaciones: ")
print(" --------------------------------------------------------- \n")
print(" 1) Sumar")
print(" 2) Restar")
print(" 3) Multiplicar")
print(" 4) Dividir")
print(" --------------------------------------------------------- \n")
operacion = int(input(" >> Ingrese una opción: "))
return operacion
def validarMenu():
operacion = menu()
while(operacion < 1 or operacion > 4):
print(" -> ERROR... OPCIÓN NO VÁLIDA")
os.system("PAUSE")
os.system("cls")
operacion = menu()
return operacion
def ejecutarOpcion(operacion, num1, num2):
if operacion == 1:
resultado = sumar(num1, num2)
elif operacion == 2:
resultado = restar(num1, num2)
elif operacion == 3:
resultado = multiplicar(num1, num2)
else:
resultado = dividir(num1, num2)
return resultado
opcion = validarMenu()
print(" \n")
while True:
try:
valor1 = int(input(" >> Ingrese un número: "))
valor2 = int(input(" >> Ingrese un número: "))
print(f"\n -> RESULTADO : {ejecutarOpcion(opcion, valor1, valor2)}")
break
except ValueError:
print("\n -> Los valores introducidos no son correctos")
os.system("PAUSE")
os.system("cls")
print(" -> Operación ejecutada correctamente. Continuación de ejecución del programa")