-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7096 from YorjanVarela/practica-yorjan
#1 python
- Loading branch information
Showing
2 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
Roadmap/01 - OPERADORES Y ESTRUCTURAS DE CONTROL/python/YorjanVarela.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#tipos de operadores en python | ||
#operadores aritmeticos | ||
suma = 2+2 | ||
resta = 2-2 | ||
multiplicacion = 2*2 | ||
division = 2/2 | ||
modulo = 2%2 #el residuo o resto de la division | ||
division_entera = 2//2 #devuelve la parte entera de la division | ||
potencia = 2**2 | ||
|
||
print(suma) | ||
print(resta) | ||
print(multiplicacion) | ||
print(division) | ||
print(modulo) | ||
print(division_entera) | ||
print(potencia) | ||
|
||
#operadores de comparacion | ||
|
||
igual_a = 2 == 2 | ||
distinto_de = 2 != 2 | ||
mayor_que = 2 > 2 | ||
menor_que = 2 < 2 | ||
mayor_o_igual_que = 2 >= 2 | ||
menor_o_igual_que = 2 <= 2 | ||
|
||
print(igual_a) | ||
print(distinto_de) | ||
print(mayor_que) | ||
print(menor_que) | ||
print(mayor_o_igual_que) | ||
print(menor_o_igual_que) | ||
|
||
#operadores logicos | ||
And = True and True | ||
Or = True or False | ||
Not = not True | ||
|
||
print(And) | ||
print(Or) | ||
print(Not) | ||
|
||
#operadores de asignacion | ||
asignacion = 2 | ||
asignacion += 2 | ||
asignacion -= 2 | ||
asignacion *= 2 | ||
asignacion /= 2 | ||
asignacion //= 2 | ||
asignacion %= 2 | ||
asignacion **= 2 | ||
|
||
print(asignacion) | ||
|
||
#operadores bit a bit | ||
bit_a_bit_and = 2 & 2 | ||
bit_a_bit_or = 2 | 2 | ||
bit_a_bit_xor = 2 ^ 2 | ||
complemento = ~2 | ||
desplazar = 2 << 2 | ||
desplazar_a_derecha = 2 >> 2 | ||
|
||
print(bit_a_bit_and) | ||
print(bit_a_bit_or) | ||
print(bit_a_bit_xor) | ||
print(complemento) | ||
print(desplazar) | ||
print(desplazar_a_derecha) | ||
|
||
#operadores de identidad | ||
identidad = 2 is 2 | ||
no_identidad = 2 is not 2 | ||
|
||
print(identidad) | ||
print(no_identidad) | ||
|
||
#operadores de pertenencia | ||
pertenece = 2 in [1, 2, 3] | ||
no_pertenece = 2 not in [1, 4, 3] | ||
|
||
print(pertenece) | ||
print(no_pertenece) | ||
|
||
#operadores de ternario | ||
edad = 18 | ||
mensaje = "Eres mayor de edad" if edad >= 18 else "Eres menor de edad" | ||
print(mensaje) # Imprimirá: Eres mayor de edad | ||
|
||
#Estructuras de control | ||
#condicionales | ||
edad = 18 | ||
if edad > 18: | ||
print("Eres mayor de edad") | ||
elif edad == 18: | ||
print("Acabas de cumplir la mayoría de edad") | ||
else: | ||
print("Eres menor de edad") | ||
|
||
#bucles | ||
for i in range(5): | ||
print(i) | ||
|
||
i = 0 | ||
while i < 5: | ||
print(i) | ||
i += 1 | ||
|
||
#otras estructuras de control | ||
|
||
numeros = [1, 2, 3, 4, 5] | ||
for numero in numeros: | ||
if numero == 3: | ||
break | ||
print(numero) | ||
|
||
for i in range(10): | ||
if i % 2 == 0: | ||
continue | ||
print(i) | ||
|
||
def mi_funcion(): | ||
# Aquí iría el código de la función, pero por ahora solo vamos a poner pass | ||
pass | ||
|
||
if 1 == 1: | ||
pass # Hacer algo | ||
else: | ||
pass # No hacer nada en este caso | ||
|
||
print(mi_funcion) | ||
|
||
#programa extra | ||
for i in range(10, 56): | ||
if i == 16: | ||
continue | ||
if i % 3 == 0: | ||
continue | ||
print(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#función basica en python | ||
|
||
print("hola mundo") #imprime cosas en pantalla | ||
|
||
#función sin parametro ni retorno | ||
|
||
def saludar(): | ||
print("¡Hola!") | ||
|
||
saludar() # Salida: ¡Hola! | ||
|
||
#funciónes con uno o varios paramatros | ||
|
||
def sumar(a, b): | ||
resultado = a + b | ||
print("La suma es:", resultado) | ||
|
||
sumar(3, 5) # Salida: La suma es: 8 | ||
|
||
#función con retorno | ||
|
||
def multiplicar(a, b): | ||
return a * b | ||
|
||
resultado = multiplicar(4, 6) | ||
print(resultado) # Salida: 24 | ||
|
||
#función dentro de otra función o función aninada | ||
|
||
def funcion_externa(x): | ||
def funcion_interna(y): | ||
return x * y | ||
return funcion_interna | ||
|
||
# Crear una función interna específica | ||
multiplicar_por_5 = funcion_externa(5) | ||
|
||
# Usar la función interna | ||
resultado = multiplicar_por_5(3) | ||
print(resultado) # Salida: 15 | ||
|
||
#funciónes que ya vienen con el lenguaje | ||
|
||
|
||
valor_absoluto = abs(5) | ||
print(valor_absoluto) | ||
|
||
length = len("hola") | ||
print(length) | ||
|
||
type = type("hola") | ||
print(type) | ||
|
||
|
||
|
||
#entre muchas otras que harian el codigo infinito pero son muchas y muy utiles cuya finalidad es evitar que escribamos el codigo desde cero. | ||
|
||
#variables local y globales | ||
|
||
# Variable global | ||
mensaje = "Hola, mundo!" | ||
|
||
def mi_funcion(): | ||
# Variable local | ||
nombre = "Juan" | ||
print(mensaje) # Podemos acceder a la variable global | ||
print(nombre) # Solo podemos acceder a nombre dentro de la función | ||
|
||
mi_funcion() | ||
print(mensaje) # Podemos acceder a mensaje fuera de la función | ||
# print(nombre) # Esto daría error, porque nombre solo existe dentro de mi_funcion() | ||
|
||
|
||
|
||
#Ejercicio extra | ||
|
||
def my_function(a, b): | ||
for i in range(1, 101): | ||
if i % 3 == 0 and i % 5 == 0: | ||
print(a, b) | ||
elif i % 3 == 0: | ||
print(a) | ||
elif i % 5 == 0: | ||
print(b) | ||
else: | ||
print(i) | ||
|
||
print(my_function("hola", "mundo")) |