Skip to content

Commit 815db40

Browse files
committed
#2 - Python
1 parent 476fbda commit 815db40

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# FUNCIONES
2+
3+
####FUNCION QUE NO ESPERA PARAMETROS####
4+
def mi_primera_funcion():
5+
print("Hola! esta es mi primera funcion")
6+
7+
mi_primera_funcion()
8+
9+
#####FUNCION CON RETORNO####
10+
11+
def funcion_retorno():
12+
return "Hola!, esta es una función de retorno"
13+
14+
print(funcion_retorno())
15+
16+
#####FUNCION CON 1 PARAMETRO#####
17+
18+
def funcion_un_arg(name):
19+
print(f'Hola {name}!')
20+
21+
funcion_un_arg("Jhan")
22+
23+
#####FUNCION CON MAS DE UN PARAMETRO#####
24+
25+
def fun_mas_arg(saludo, name):
26+
print(f"{saludo}, {name}!")
27+
28+
fun_mas_arg("Hola", "Jhan")
29+
30+
#####FUNCION CON VALOR POR DEFECTO####
31+
32+
def valor_por_defecto(name="Mundo"):
33+
print(f"Hola {name}")
34+
35+
valor_por_defecto("Pier")
36+
valor_por_defecto()
37+
38+
#####FUNCION CON MULTIPLES ARGUMENTOS *args ####
39+
40+
def suma_args(*args): #Los parametros recibidos seran converidos en una tupla
41+
total = 0
42+
for n in args:
43+
total += n
44+
return print(total)
45+
46+
suma_args(1,2,3)
47+
48+
49+
####FUNCION CON MULTIPLES ARGUMENTOS KEY/VALUE####
50+
51+
def resta_kwargs(**kwargs):
52+
suma = 0
53+
for key, value in kwargs.items():
54+
print (f"{key} = {value}")
55+
suma += value
56+
return print(suma)
57+
58+
resta_kwargs(a=20, b=10, c= 5)
59+
60+
61+
#####FUNCIONES DENTRO DE FUNCIONES####
62+
63+
def calculadora():
64+
65+
def suma(n1=0, n2=0):
66+
return n1 + n2
67+
print(suma(2,3))
68+
69+
def resta(n1=0, n2=0):
70+
return n1 - n2
71+
print(resta(4,5))
72+
73+
def multiplicacion(n1=0, n2=0):
74+
return n1 * n2
75+
print(multiplicacion(5,6))
76+
77+
def division(n1=0, n2=0):
78+
return n1 / n2
79+
print(division(7,8))
80+
81+
calculadora()
82+
83+
84+
###FUNCIONES DEL LENGUAJE###
85+
86+
#-----Funciones de cadenas
87+
88+
#--IMPRESION
89+
print("Este texto fue impreso con la funcion print()")
90+
91+
#--CADENAS
92+
minuscula = "ESTE TEXTO FUE CONVERTIDO EN MINUSCULAS CON LA FUNCION lower()"
93+
print(minuscula.lower())
94+
mayuscula = "este texto fue convertido a mayusculas con la funcion upper()"
95+
print(mayuscula.upper())
96+
97+
#----FUNCION PARA TIPO DE DATOS
98+
99+
mi_arreglo = [1,2,3,4,5]
100+
print(type(mi_arreglo))
101+
102+
####CONCEPTO DE VARIABLE LOCAL Y GLOBAL####
103+
104+
#VARIABLE GLOBAL
105+
mi_variable_local = "Hola soy una variable local"
106+
107+
def funcion_local():
108+
print(mi_variable_local)
109+
110+
funcion_local()
111+
112+
#VARIABLE LOCAL
113+
114+
def funcion_local1():
115+
variable = "Hola soy una variable local"
116+
return print(variable)
117+
funcion_local1()
118+
119+
print("En esta linea no puedo acceder la variable de la funcion1")
120+
121+
122+
123+
#EJERCICIO EXTRA
124+
125+
def extra(texto1, texto2):
126+
contador = 0
127+
for numero in range(1, 101):
128+
if numero % 3 == 0 and numero % 5 == 0:
129+
print(texto1 + texto2)
130+
elif numero % 3 == 0:
131+
print(texto1)
132+
elif numero % 5 == 0:
133+
print(texto2)
134+
else:
135+
print(numero)
136+
contador +=1
137+
138+
return contador
139+
140+
print(extra("Fizz", "Buzz"))
141+
142+

0 commit comments

Comments
 (0)