forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
734f55f
commit 7e3e9ab
Showing
3 changed files
with
190 additions
and
81 deletions.
There are no files selected for viewing
31 changes: 18 additions & 13 deletions
31
Roadmap/00 - SINTAXIS, VARIABLES, TIPOS DE DATOS Y HOLA MUNDO/python/saicobys.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 |
---|---|---|
@@ -1,19 +1,24 @@ | ||
# Python: https://www.python.org/ | ||
""" | ||
Este es un comentario de varias líneas | ||
# URL del sitio web oficial de Python: https://www.python.org/ | ||
|
||
# Comentarios en Python. | ||
# Comentario de una sola linea: se utiliza el simbolo # al inicio. | ||
|
||
""" | ||
Comentario multilinea: | ||
Se utilizan tres comillas dobles (""" """) al principio y al final. | ||
Puedes usar comillas simples triples (''' ''') también. | ||
""" | ||
|
||
# creación de variable de prueba | ||
variable_prueba = 420 # Python no tiene constantes | ||
# Variables y constantes | ||
nombre_lenguaje = "Python" # Variable: Almacena el nombre del lenguaje, puede cambiar su valor. | ||
PI = 3.14159 # Constante: Almacena el valor de pi, no debe cambiar. | ||
|
||
# Tipos de datos primitivos | ||
string = "Hola Jacob" | ||
integer = 99 | ||
float = 2.20 | ||
boolean = True | ||
NoneType = None | ||
complex_number = 1 + 4j | ||
saludo = "Hola, mundo!" # str (cadena de texto) | ||
edad = 30 # int (número entero) | ||
altura = 1.75 # float ( numero decimal) | ||
es_estudiante = True # bool (booleano: True o False) | ||
nada = None # NoneType (representa la ausencia de valor) | ||
|
||
# imprimir por terminal | ||
print("¡Hola, Python!") | ||
# Imprimir por terminal | ||
print(f"Hola, {nombre_lenguaje}!") # Imprime el saludo usando f-string para insertar la variable. |
106 changes: 106 additions & 0 deletions
106
Roadmap/01 - OPERADORES Y ESTRUCTURAS DE CONTROL/python/AbelPerezCollado.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,106 @@ | ||
from random import randint | ||
n1 = randint(1,10) | ||
n2 = randint(1,10) | ||
|
||
# Operadores aritmeticos | ||
print(f'Suma {n1} + {n2} = {n1+n2}') | ||
print(f'Resta {n1} - {n2} = {n1-n2}') | ||
print(f'Multiplicacion {n1} * {n2} = {n1*n2}') | ||
print(f'Division {n1} / {n2} = {n1/n2}') | ||
print(f'Resto {n1} % {n2} = {n1%n2}') | ||
print(f'Potencia {n1} ** {n2} = {n1**n2}') | ||
print(f'Division entera {n1} // {n2} = {n1//n2}') | ||
print(f'Suma {n1} + {n2} = {n1+n2}') | ||
|
||
# Operadores Logicos | ||
print(2==2 and 1==1) | ||
print(n1==n2 or 1==1) | ||
print(not n1==n2) | ||
|
||
|
||
# Operadores de comparación | ||
print("Igualdad: 1 == 1 es", 1 == 1) | ||
print("Desigualdad: a != b es", 'a' != 'b') | ||
print("Mayor que: 10 > 3 es", 10 > 3) | ||
print("Menor que: 2 < 3 es", 2 < 3) | ||
print("Mayor o igual que: 2 >= 2 es", 2 >= 2) | ||
print("Menor o igual que: 2 <= 7 es", 2 <= 7) | ||
|
||
# Operadores de asignación | ||
a = 5 | ||
print(f'Operador a = 5 ->{a}') | ||
a += 5 | ||
print(f'Operador a += 5 ->{a}') | ||
a -= 5 | ||
print(f'Operador a -= 5 ->{a}') | ||
a *= 3 | ||
print(f'Operador a *= 3 ->{a}') | ||
a /= 3 | ||
print(f'Operador a /= 3 -> {a}') | ||
a %=3 | ||
print(f'Operador a %= 3 -> {a}') | ||
a **=3 | ||
print(f'Operador a **= 3 -> {a}') | ||
a //=3 | ||
print(f'Operador a //= 3 -> {a}') | ||
|
||
|
||
# Operadores de identidad | ||
a = 3 | ||
b = 3 | ||
c = 4 | ||
print(f'3 is 3 -> {a is b}') | ||
print(f'4 is not 3 -> {c is not b}') | ||
|
||
|
||
# Operadores de pertenencia | ||
a = [1,2,3,4,5] | ||
print(f'1 in a -> {1 in a}') | ||
print(f'7 not in a -> {7 not in a}') | ||
|
||
# Operadores de bits | ||
print("AND bit a bit: 2 & 3 es", 2 & 3) | ||
print("OR bit a bit: 2 | 3 es", 2 | 3) | ||
print("XOR bit a bit: 2 ^ 3 es", 2 ^ 3) | ||
print("NOT bit a bit: ~2 es", ~2) | ||
print("Desplazamiento a la derecha: 2 >> 1 es", 2 >> 1) | ||
print("Desplazamiento a la izquierda: 2 << 1 es", 2 << 1) | ||
|
||
# Estructuras de control condicionales iterativas, excepciones | ||
name = 'Abel' | ||
apellido = 'Perez' | ||
#Condicionales | ||
if name is not apellido: | ||
print('Sentencia IF') | ||
if name is apellido: | ||
pass | ||
elif 'a' in apellido: | ||
print('Sentencia elif') | ||
else: | ||
print('Sentencia else') | ||
|
||
# Iteraciones | ||
for l in name: | ||
print(l) | ||
|
||
n =0 | ||
while n <= 4: | ||
print(n) | ||
n += 1 | ||
|
||
# Excepciones | ||
a = 1 | ||
b = 2 | ||
try: | ||
print(len(a)) | ||
except Exception as err: | ||
print(err) | ||
|
||
# Extra: Programa que imprima por consola todos los numeros comprendidos entre 10 y 55 incluidos | ||
# pares y que no son ni el 16 ni multiplos de 3 | ||
for n in range(10,56): | ||
if not n % 3 == 0 and n != 16 and n % 2 == 0: | ||
print(n) | ||
|
||
|
||
|
134 changes: 66 additions & 68 deletions
134
Roadmap/01 - OPERADORES Y ESTRUCTURAS DE CONTROL/python/saicobys.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 |
---|---|---|
@@ -1,82 +1,80 @@ | ||
# Operadores aritméticos | ||
x = 10 | ||
y = 3 | ||
suma = x + y | ||
resta = x - y | ||
multiplicacion = x * y | ||
division = x / y | ||
division_entera = x // y | ||
modulo = x % y | ||
potencia = x ** y | ||
""" Operadores en Python: """ | ||
# Operadores Aritméticos | ||
a = 10 | ||
b = 3 | ||
print(f"Suma: {a + b}") # Suma | ||
print(f"Resta: {a - b}") # Resta | ||
print(f"Multiplicación: {a * b}") # Multiplicación | ||
print(f"División: {a / b}") # División | ||
print(f"División entera: {a // b}") # División entera | ||
print(f"Módulo: {a % b}") # Resto de la división | ||
print(f"Exponenciación: {a ** b}") # Potencia | ||
|
||
print("Suma:", suma) | ||
print("Resta:", resta) | ||
print("Multiplicacion:", multiplicacion) | ||
print("Division:", division) | ||
print("division entera:", division_entera) | ||
print("Modulo:", modulo) | ||
print("Potencia:", potencia) | ||
# Operadores de Comparación | ||
x = 5 | ||
y = 8 | ||
print(f"x == y: {x == y}") # Igual a | ||
print(f"x != y: {x != y}") # Distinto de | ||
print(f"x > y: {x > y}") # Mayor que | ||
print(f"x < y: {x < y}") # Menor que | ||
print(f"x >= y: {x >= y}") # Mayor o igual que | ||
print(f"x <= y: {x <= y}") # Menor o igual que | ||
|
||
# Operadores de comparacion | ||
a = 5 | ||
b = 8 | ||
print("a == b:", a == b) | ||
print("a != b:", a != b) | ||
print("a > b:", a > b) | ||
print("a < b:", a < b) | ||
print("a >= b:", a >= b) | ||
print("a <= b:", a <= b) | ||
# Operadores Lógicos | ||
p = True | ||
q = False | ||
print(f"p and q: {p and q}") # AND lógico (ambos deben ser True) | ||
print(f"p or q: {p or q}") # OR lógico (al menos uno debe ser True) | ||
print(f"not p: {not p}") # NOT lógico (invierte el valor de verdad) | ||
|
||
# Operadores lógicos | ||
c = True | ||
d = False | ||
print("c and d:", c and d) | ||
print("c or d:", c or d) | ||
print("not c:", not c) | ||
# Operadores de Asignación | ||
z = 20 | ||
z += 5 # z = z + 5 | ||
print(f"z += 5: {z}") | ||
z -= 3 # z = z - 3 | ||
print(f"z -= 3: {z}") | ||
z *= 2 # z = z * 2 | ||
print(f"z *= 2: {z}") | ||
z /= 4 # z = z / 4 | ||
print(f"z /= 4: {z}") | ||
|
||
# Operadores de asignación | ||
e = 15 | ||
e += 5 # e = e + 5 | ||
print("e += 5:", e) | ||
e -= 3 # e = e - 3 | ||
print("e -= 3:", e) | ||
# Operadores de Identidad | ||
lista1 = [1, 2, 3] | ||
lista2 = [1, 2, 3] | ||
lista3 = lista1 | ||
print(f"lista1 is lista2: {lista1 is lista2}") # False (objetos diferentes) | ||
print(f"lista1 is lista3: {lista1 is lista3}") # True (misma referencia) | ||
|
||
# Operadores de identidad | ||
f = [1, 2, 3] | ||
g = [1, 2, 3] | ||
h = f | ||
print("f is g:", f is g) # False (objetos diferentes) | ||
print("f is h:", f is h) # True (misma referencia) | ||
print("f == g:", f == g) # True (mismo contenido) | ||
# Operadores de Pertenencia | ||
print(f"1 in lista1: {1 in lista1}") # True | ||
print(f"4 in lista1: {4 in lista1}") # False | ||
|
||
# Operadores de pertenencia | ||
lista = [1, 2, 3, 4] | ||
print("1 in lista:", 1 in lista) | ||
print("5 in lista:", 5 in lista) | ||
|
||
# Condicionales | ||
""" Estructuras de Control en Python: """ | ||
# Condicionales (if, elif, else) | ||
edad = 25 | ||
|
||
if edad < 18: | ||
print("Eres menor de edad") | ||
elif edad >= 18 and edad < 65: | ||
print("Eres adulto") | ||
print("Eres menor de edad") | ||
elif 18 <= edad < 65: # Combina comparación y operadores lógicos | ||
print("Eres adulto") | ||
else: | ||
print("Eres jubilado") | ||
print("Eres adulto mayor") | ||
|
||
# Iterativas (bucles) | ||
for i in range(1, 6): # Imprime números del 1 al 5 | ||
print(i) | ||
# Bucles (for , while) | ||
for i in range(1, 6): # Bucle for: itera sobre un rango de números | ||
print(i) | ||
|
||
numero = 1 | ||
while numero <= 5: # Imprime números del 1 al 5 | ||
print(numero) | ||
numero += 1 | ||
contador = 0 | ||
while contador < 5: # Bucle while: itera mientras se cumpla una condición | ||
print(contador) | ||
contador += 1 | ||
|
||
# Excepciones | ||
# Excepciones (try, except, else, finally) | ||
try: | ||
resultado = 10 / 0 # División por cero (error) | ||
except ZeroDivisionError as e: | ||
print("Error:", e) | ||
finally: | ||
print("Fin del programa") | ||
resultado = 10 / 0 # División por cero (genera una excepción) | ||
except ZeroDivisionError: | ||
print("Error: División por cero no permitida") | ||
else: # Se ejecuta si no hubo excepciones | ||
print("El resultado es:", resultado) | ||
finally: # Se ejecuta siempre, haya o no excepciones | ||
print("Fin del programa") |