-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.py
64 lines (63 loc) · 2.12 KB
/
functions.py
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
# Ahora vamos a ver como hacer para "dividir y conquistar".
# Para ello vamos a crear algo llamado función.
# Una función es un bloque de código que puede ser reutilizado. Puede recibir parámetros y retornar una salida.
# Ejemplo:
def suma (a, b):
return a + b # La palabra clave return indica que la función debe devolver el valor que se especifique.
def resta (a, b):
return a - b
def multiplicacion (a, b):
return a * b
def division (a, b):
return a / b
def factorial (n):
fact = 1
for i in range(1, n + 1):
fact *= i
return fact
def potenciacion (a, b):
return a ** b
def menu ():
print("LISTA de OPERACIONES:")
print("1) SUMA")
print("2) RESTA")
print("3) MULTIPLICACION")
print("4) DIVISION")
print("5) FACTORIAL")
print("6) POTENCIACION")
return # Si no se especifica nada, return acaba con la función.
end = False
while (end == False):
menu()
op = int(input("Ingrese la operacion a realizar: "))
if (op == 1):
a = int(input("Ingrese in numero entero: "))
b = int(input("Ingrese otro numero entero: "))
print(str(suma(a, b)))
if (op == 2):
a = int(input("Ingrese in numero entero: "))
b = int(input("Ingrese otro numero entero: "))
print(str(resta(a, b)))
if (op == 3):
a = int(input("Ingrese in numero entero: "))
b = int(input("Ingrese otro numero entero: "))
print(str(multiplicacion(a, b)))
if (op == 4):
a = int(input("Ingrese in numero entero: "))
b = int(input("Ingrese otro numero entero: "))
print(str(division(a, b)))
if (op == 5):
a = int(input("Ingrese in numero entero: "))
print(str(factorial(a)))
if (op == 6):
a = int(input("Ingrese in numero entero: "))
b = int(input("Ingrese otro numero entero: "))
print(str(potenciacion(a, b)))
if (op != 1 and op != 2 and op != 3 and op != 4 and op != 5 and op != 6):
continue
print("Quieres hacer otra operacion? [Y/n]")
cont = input()
if (cont == "N" or cont == "n"):
end = True
input("Presione ENTER para continuar...")
exit(0)