Skip to content

Commit 535bd39

Browse files
authored
Merge pull request mouredev#6521 from JhonMarin12/main
#1 - Python
2 parents 76da3a5 + a2ab116 commit 535bd39

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#Python cuenta con multiples operadores, a continuación se enlistan los diferentes que existen
2+
3+
#Operadores numericos
4+
5+
suma = 13 + 12
6+
resta = 45 - 12
7+
division = 21 / 9
8+
multiplicacion = 12 * 89
9+
potencia = 12 ** 12
10+
division_entera = 45 // 6
11+
modulo = 12 % 8
12+
13+
#Operadores de comparación
14+
igualdad = 'Hola' == 'Hola'
15+
mayor_que = 5 > 12 #tambien existe el mayor o igual >=
16+
menor_que = 6 < 0 #tambien existe el menor o igual <=
17+
diferente = 'hola' != 'hola'
18+
19+
#operadores booleanos
20+
y_and = True and False
21+
o_or = (5 > 32) or ('perro' != 'gato')
22+
no_not = not(True)
23+
24+
#Operaciones con strings
25+
concatenacion = 'Hola' + ' como estas?'
26+
repeticion = 'hola' * 3 #da 'holaholahola'
27+
28+
# condicionales
29+
a = 89
30+
b = 12
31+
32+
if a > b:
33+
print(f'El numero {a} es mayor que {b}')
34+
elif b > a:
35+
print(f'El numero {a} es menor que {b}')
36+
else:
37+
print('a y b son iguales')
38+
39+
#Ciclos
40+
41+
#Ciclo for
42+
for i in range(0,10):
43+
pass
44+
45+
#Ciclo while
46+
# while True:
47+
# #Hacer esto
48+
# pass
49+
50+
def operar(a,b):
51+
try:
52+
operacion = a/b
53+
print(a/b)
54+
except ZeroDivisionError:
55+
print("No se peude dividir entre cero")
56+
57+
operar(12,0)
58+
59+
60+
# Ejercicio opcional
61+
for i in range(10,56):
62+
if i % 2 == 0 and i != 16 and not(i % 3 == 0):
63+
print(i)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# En este archivo trabajaremos con funciones
2+
# La forma basica de definir una funcione es:
3+
def nombre_funcion(parametro1):
4+
#hacer funcion
5+
return None #Retornar un valor
6+
7+
# Funcion si parametros
8+
def saludar():
9+
return "Hola, como estas?"
10+
11+
# Funcion con un parametro
12+
def saludo_personalizado(nombre:str):
13+
return f"Hola {nombre.capitalize()}, como estas?"
14+
15+
print(saludo_personalizado('Jhon'))
16+
17+
def saludo_edad(nombre:str, edad:int):
18+
return f"Hola, mi nombres {nombre}, tengo {edad} años"
19+
20+
# Se pueden usar funciones dentro de funciones?
21+
def funcion_externa(a:float, b:float):
22+
def funcion_interna(c:float):
23+
return c ** 2
24+
return a * funcion_interna(b)
25+
26+
print(funcion_externa(2,2))
27+
28+
# Tambien es aplicable para hacer recursividad, sin embargo este concepto trata de que usamos la misma funcion para obtener algun rasultado, sin necesidad de una funcion interna
29+
30+
#factorial
31+
def factorial(n:int):
32+
if n > 0:
33+
if n == 0 or n == 1:
34+
return 1
35+
else:
36+
return n * factorial(n-1)
37+
else:
38+
return None
39+
40+
print(factorial(5))
41+
42+
#Funciones integradas en python:
43+
length = len('Hola como estas?')
44+
# funciones para hacer casting float(), list(), int(), str()
45+
max(12,4,1)
46+
min(12,51,1)
47+
#Existen muchas...
48+
49+
# Scope de las funciones
50+
variable_global = 10
51+
def operacion():
52+
variable_local = 5
53+
return variable_global - variable_local
54+
55+
# Ejercicio opcional
56+
def FizzBuzz(a='Fizz', b='Buzz'):
57+
contador = 0
58+
for i in range(0,101):
59+
if i % 3 == 0 and i % 5 == 0:
60+
print(f"{i} - {a}{b}")
61+
elif i % 3 == 0:
62+
print(f"{i} - {a}")
63+
elif i%5 == 0:
64+
f"{i} - {b}"
65+
else:
66+
contador += 1
67+
return contador
68+
69+
print(FizzBuzz())

0 commit comments

Comments
 (0)