1+ # Funciones
2+
3+ # Sin parámetros ni retorno
4+
5+ def saludo ():
6+ print ('Hola mundo' )
7+
8+ saludo ()
9+
10+ # Con un parámetros
11+
12+ def dato (nombre ):
13+ print (f'Mi nombre es { nombre } ' )
14+
15+ dato ('Manuel' )
16+
17+ # Con varios parámetros
18+
19+ def datos (nombre ,apellido ,edad ):
20+ print (f'Mi nombre y apellido es { nombre } { apellido } y tengo { edad } de edad' )
21+
22+ datos ('Manuel' ,'Morales' ,'28' )
23+
24+ # Con retorno
25+
26+ def suma (num1 ,num2 ):
27+ return num1 + num2
28+
29+ resultado = suma (30 ,20 )
30+
31+ print (f'El resultado de la suma es: { resultado } ' )
32+
33+
34+ def dividir (num1 ,num2 ):
35+ if num2 == 0 :
36+ return 'Error: División por cero'
37+ return num1 / num2
38+
39+ resultado = dividir (30 ,2 )
40+
41+ print (f'El resultado de la division es: { resultado } ' )
42+
43+ # funciones dentro de funciones
44+
45+ def resultado_resta (num5 ,num6 ):
46+
47+ def resta (num3 ,num4 ):
48+ return num3 - num4
49+
50+ return resta (num5 ,num6 )
51+
52+ resultado = resultado_resta (30 ,10 )
53+
54+ print (resultado )
55+
56+ # funciones ya creadas en el lenguaje
57+
58+ # 1. print()
59+ print ("Hola, Python!" )
60+
61+ # 2. len()
62+ cadena = "Python"
63+ longitud = len (cadena )
64+ print (longitud )
65+
66+ # 3. type()
67+ numero = 10
68+ print (type (numero ))
69+
70+ # 4. input()
71+
72+ nombre = input ("Ingrese su nombre: " )
73+ print ("Hola," , nombre )
74+
75+ # 5. int()
76+
77+ numero = "10"
78+ numero_entero = int (numero )
79+ print (numero_entero )
80+
81+ # 6. float()
82+
83+ precio = "99.99"
84+ precio_float = float (precio )
85+ print (precio_float )
86+
87+ # 7. float()
88+
89+ edad = 25
90+ edad_str = str (edad )
91+ print (edad_str )
92+
93+ # 8. abs()
94+
95+ numero = - 10
96+ valor_absoluto = abs (numero )
97+ print (valor_absoluto )
98+
99+ # 9. round()
100+
101+ numero = 3.14159
102+ numero_redondeado = round (numero , 2 )
103+
104+ # 10. max(), min()
105+
106+ numeros = [1 , 5 , 2 , 8 , 3 ]
107+ maximo = max (numeros )
108+ minimo = min (numeros )
109+ print (maximo )
110+ print (minimo )
111+
112+ # 11. sum()
113+
114+ numeros = [1 , 2 , 3 , 4 , 5 ]
115+ suma = sum (numeros )
116+ print (suma )
117+
118+ # Funcion con una variable local
119+
120+ def mi_funcion ():
121+ x = 12
122+ print (x )
123+
124+ mi_funcion ()
125+
126+ # Funcion con una variable global
127+
128+ variable = 'Hola mundo'
129+
130+ def mi_codigo ():
131+ print (variable )
132+
133+ mi_codigo ()
134+
135+ print (variable )
136+
137+ # DIFICULTAD EXTRA
138+
139+ def numbers (number_1 ,number_2 ):
140+ count = 0
141+ for numero in range (1 ,101 ):
142+ if numero % 3 == 0 and numero % 5 == 0 :
143+ print (number_1 + ' ' + number_2 )
144+ elif numero % 3 == 0 :
145+ print (number_1 )
146+ elif numero % 5 == 0 :
147+ print (number_2 )
148+ else :
149+ print (numero )
150+ count += 1
151+ return count
152+
153+ print (numbers ('Number_1' , 'Number_2' ))
0 commit comments