-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.py
More file actions
74 lines (56 loc) · 1.75 KB
/
Copy pathcalc.py
File metadata and controls
74 lines (56 loc) · 1.75 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
#funciones calc.py
def menu():
print("calc.py")
print("=========================")
print("1. Sumar")
print("2. Restar")
print("3. Multiplicar")
print("4. Dividir")
print("5. Resto entero de la division")
print("0. Salir")
def leer_opcion():
print("Elige una opcion:")
return int(input())
def pedir_numero(n=2):
listaNumeros = []
for i in range(0,n):
print("Introduce numero: ")
listaNumeros.append(int(input()))
return listaNumeros
#main
salida = not False
while salida:
menu()
opcion = leer_opcion()
if int(opcion) == 1:
numeros = pedir_numero(3)
suma = sum(numeros)
print("La suma es: " + str(suma))
elif int(opcion) == 2:
numeros = pedir_numero(3)
resta = numeros[0] - sum(numeros[1:])
print("La resta es: " + str(resta))
elif int(opcion) == 3:
numeros = pedir_numero(3)
multiplicacion = 1
for numero in numeros:
multiplicacion *= numero
print("La multiplicacion es: " + str(multiplicacion))
elif int(opcion) == 4:
numeros = pedir_numero(2)
if numeros[1] == 0:
print("No se puede dividir entre 0")
else:
division = numeros[0] / numeros[1]
print("La division es: " + str(division))
elif int(opcion) == 5:
numeros = pedir_numero(2)
if numeros[1] == 0:
print("No se puede dividir entre 0")
else:
resto = numeros[0] % numeros[1]
print("El resto de la division es: " + str(resto))
elif int(opcion) == 0:
print("Saliendo del programa...")
salida = False
print("Fin del programa")