Skip to content

Commit 544d997

Browse files
committed
Reto#02 - Python
1 parent 3886cd8 commit 544d997

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
PI = 3.1416
2+
3+
'''
4+
EJERCICIO 1:
5+
Crea ejemplos de funciones básicas que representen las diferentes
6+
posibilidades del lenguaje.
7+
8+
Sin parámetros ni retorno, con uno o varios parámetros, con retorno ...
9+
'''
10+
11+
def no_return_no_params():
12+
print("No return, no parameters function")
13+
a = int(input("Enter a number: "))
14+
b = int(input("Enter another number: "))
15+
16+
print(f"{a} + {b} = {a + b}")
17+
18+
def no_return(a, b):
19+
print("\nNo return function")
20+
print(f"{a} + {b} = {a + b}")
21+
22+
def return_params(a, b):
23+
print("\nFunction with parameters and return")
24+
return a + b
25+
26+
def multiple_params(*languages):
27+
print("\nFunction with multiple parameters")
28+
for language in languages:
29+
print(f"Hello, {language}!")
30+
31+
'''
32+
---------------------------------------------------------------------
33+
EJERCICIO 2:
34+
Comprueba si puedes crear funciones dentro de funciones.
35+
'''
36+
37+
def outer_function(param):
38+
print("\nFunction inside other function")
39+
def inner_function():
40+
print(f"Hello, {param}")
41+
inner_function()
42+
43+
'''
44+
---------------------------------------------------------------------
45+
EJERCICIO 3:
46+
Utiliza algun ejemplo de funciones ya creadas en el lenguaje
47+
'''
48+
49+
def builtin_functions(nombre, numero):
50+
print("\nFunctions that use a builtin function")
51+
print(f"String [{nombre}] contains {len(nombre)} characters")
52+
print(f"Integer {numero} converted to a string {int(numero)}")
53+
54+
'''
55+
---------------------------------------------------------------------
56+
EJERCICIO 4:
57+
Pon a prueba el concepto de variable LOCAL y GLOBAL
58+
'''
59+
60+
def global_local(variable1, variable2):
61+
print(f"This is a global variable {variable1}")
62+
print(f"This is a local variable {variable2}")
63+
64+
'''
65+
---------------------------------------------------------------------
66+
DIFICULTAD EXTRA:
67+
Crea una funcion que reciba dos parametros de tipo cadena de texto y retorne un numero.
68+
'''
69+
def dif_extra(cadena1, cadena2):
70+
i = 0
71+
for numero in range(1,101):
72+
if numero % 3 == 0 and numero % 5 == 0:
73+
print(f"{cadena1}{cadena2}")
74+
elif numero % 3 == 0:
75+
print(f"{cadena1}")
76+
elif numero % 5 == 0:
77+
print(f"{cadena2}")
78+
else:
79+
print(numero)
80+
i += 1
81+
return i
82+
83+
def main():
84+
e = 2.71
85+
86+
no_return_no_params()
87+
no_return(5, 4)
88+
print("8 + 3 =", return_params(8, 3))
89+
multiple_params("Python", "C", "Java")
90+
outer_function("world!")
91+
builtin_functions("Mouredev", 50)
92+
global_local(PI, e)
93+
print("Numeros:", dif_extra("hola", "mundo"))
94+
95+
96+
97+
98+
if __name__ == '__main__':
99+
main()

0 commit comments

Comments
 (0)