-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into KAFKA_Joaquin
- Loading branch information
Showing
328 changed files
with
123,567 additions
and
109 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION1/EJERCICIO1/ejercicio1.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 @@ | ||
print('Hola Mundo') |
2 changes: 2 additions & 0 deletions
2
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION1/EJERCICIO2/ejercicio2.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,2 @@ | ||
nombre : str = ('Alex') | ||
print(f"Hola {nombre}") |
20 changes: 20 additions & 0 deletions
20
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION2/EJERCICIO1/ejercicio1.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,20 @@ | ||
|
||
def calcular_inversion(inversion, interes, años): | ||
inversion_final = inversion * (1 + interes/100) ** años | ||
return inversion_final | ||
|
||
|
||
def main(): | ||
try: | ||
inversion = float(input("¿Cuánto quieres invertir?: ")) | ||
interes = float(input("¿Cuál es el interés anual?: ")) | ||
años = int(input("¿Cuántos años vas a mantener la inversión?: ")) | ||
inversion_generada = calcular_inversion(inversion, interes, años) | ||
interes_generado = inversion_generada - inversion | ||
print(f"En {años} años habrás recibido {interes_generado:.2f}€ de interés") | ||
|
||
except ValueError: | ||
print("Error: Introduce un número válido") | ||
|
||
if __name__ == "__main__": | ||
main() |
46 changes: 46 additions & 0 deletions
46
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION3/EJERCICIO1/ejercicio1.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,46 @@ | ||
def calcular_inversion(inversion, interes, años): | ||
inversion_final = inversion * (1 + interes / 100) ** años | ||
return inversion_final | ||
|
||
def main(): | ||
while True: | ||
try: | ||
print("Hola. Bienvenido al sistema de cálculo de inversiones. ¿Qué quieres hacer?") | ||
print("[1] Calcular una inversión") | ||
print("[X] Salir") | ||
opcion = input("Elige una opción: ").strip().upper() | ||
|
||
if opcion == '1': | ||
while True: | ||
try: | ||
inversion = float(input("¿Cuánto quieres invertir?: ")) | ||
interes = float(input("¿Cuál es el interés anual?: ")) | ||
años = int(input("¿Cuántos años vas a mantener la inversión?: ")) | ||
|
||
inversion_final = calcular_inversion(inversion, interes, años) | ||
interes_ganado = inversion_final - inversion | ||
|
||
print(f"En {años} años habrás recibido {interes_ganado:.2f}€ de interés.") | ||
print("¿Qué quieres hacer ahora?") | ||
print("[1] Calcular una nueva inversión") | ||
print("[X] Salir") | ||
opcion = input("Elige una opción: ").strip().upper() | ||
|
||
if opcion == 'X': | ||
print("¡Nos vemos!") | ||
exit() | ||
elif opcion != '1': | ||
print("Opción no válida. Por favor, elige una opción válida.") | ||
except ValueError: | ||
print("Error: Introduce un número válido") | ||
elif opcion == 'X': | ||
print("¡Nos vemos!") | ||
exit() | ||
else: | ||
print("Opción no válida. Por favor, elige una opción válida.") | ||
|
||
except ValueError: | ||
print("Error: Introduce un número válido") | ||
|
||
if __name__ == "__main__": | ||
main() |
14 changes: 14 additions & 0 deletions
14
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION4/EJERCICIO1/ejercicio1.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,14 @@ | ||
def es_primo(numero): | ||
if numero <= 1: | ||
return False | ||
for i in range(2, int(numero ** 0.5) + 1): | ||
if numero % i == 0: | ||
return False | ||
return True | ||
|
||
def mostrar_primos(inicio, fin): | ||
for numero in range(inicio, fin + 1): | ||
if es_primo(numero): | ||
print(numero) | ||
|
||
mostrar_primos(10, 50) |
14 changes: 14 additions & 0 deletions
14
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION4/EJERCICIO1/ejercicio2.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,14 @@ | ||
def es_primo(numero): | ||
if numero <= 1: | ||
return False | ||
for i in range(2, int(numero ** 0.5) + 1): | ||
if numero % i == 0: | ||
return False | ||
return True | ||
|
||
numero = 29 | ||
if es_primo(numero): | ||
print(f"El número {numero} es primo.") | ||
else: | ||
print(f"El número {numero} no es primo.") | ||
|
10 changes: 10 additions & 0 deletions
10
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION4/EJERCICIO1/ejercicio3.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,10 @@ | ||
def es_bisiesto(año): | ||
if (año % 4 == 0 and año % 100 != 0) or (año % 400 == 0): | ||
return True | ||
return False | ||
|
||
año = 2024 | ||
if es_bisiesto(año): | ||
print(f"El año {año} es bisiesto.") | ||
else: | ||
print(f"El año {año} no es bisiesto.") |
9 changes: 9 additions & 0 deletions
9
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION4/EJERCICIO2/ejercicio2.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,9 @@ | ||
|
||
import requests | ||
import pandas | ||
|
||
def main(): | ||
print("¡Hola, Mundo!") | ||
|
||
if __name__ == "__main__": | ||
main() |
2 changes: 2 additions & 0 deletions
2
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION4/EJERCICIO2/requirements.txt
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,2 @@ | ||
requests | ||
pandas |
17 changes: 17 additions & 0 deletions
17
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION4/EJERCICIO3/ejercicio3.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,17 @@ | ||
import requests | ||
|
||
def obtener_usuario_aleatorio(): | ||
url = "https://randomuser.me/api" | ||
response = requests.get(url) | ||
|
||
if response.status_code == 200: | ||
data = response.json() | ||
usuario = data['results'][0] | ||
nombre = usuario['name']['first'] | ||
apellidos = usuario['name']['last'] | ||
print(f"Nombre: {nombre}, Apellidos: {apellidos}") | ||
else: | ||
print("Error al realizar la petición") | ||
|
||
if __name__ == "__main__": | ||
obtener_usuario_aleatorio() |
140 changes: 140 additions & 0 deletions
140
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION5/EJERCICIO1/ejercicio1.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,140 @@ | ||
import pandas as pd | ||
|
||
# Leer el archivo CSV | ||
df = pd.read_csv('pokemon_data.csv') | ||
|
||
# IMPRIMIR TODOS LOS VALORES | ||
print("TODOS LOS VALORES:") | ||
print(df) | ||
|
||
# IMPRIMIR LOS PRIMEROS 5 | ||
print("\nPRIMEROS 5:") | ||
print(df.head()) | ||
|
||
# IMPRIMIR LOS ÚLTIMOS 5 | ||
print("\nÚLTIMOS 5:") | ||
print(df.tail()) | ||
|
||
# OBTENER NOMBRES DE LAS COLUMNAS | ||
print("\nNOMBRES DE LAS COLUMNAS:") | ||
print(df.columns) | ||
|
||
# OBTENER TODOS LOS NOMBRES | ||
print("\nTODOS LOS NOMBRES:") | ||
print(df['Name']) | ||
|
||
# OBTENER TODOS LOS NOMBRES Y VELOCIDADES | ||
print("\nTODOS LOS NOMBRES Y VELOCIDADES:") | ||
print(df[['Name', 'Speed']]) | ||
|
||
# LOS PRIMEROS 5 NOMBRES USANDO [::] | ||
print("\nPRIMEROS 5 NOMBRES USANDO [::]:") | ||
print(df['Name'][:5]) | ||
|
||
# OBTENER TODAS LAS FILAS | ||
print("\nTODAS LAS FILAS:") | ||
print(df.iloc[:]) | ||
|
||
# OBTENER UN RANGO DE FILAS | ||
print("\nRANGO DE FILAS (5-10):") | ||
print(df.iloc[5:10]) | ||
|
||
# OBTENER EL NOMBRE DE LA FILA 10 | ||
print("\nNOMBRE DE LA FILA 10:") | ||
print(df.iloc[9]['Name']) | ||
|
||
# ITERAR POR TODOS Y MOSTRAR EL ÍNDICE Y NOMBRE DE CADA FILA | ||
print("\nÍNDICE Y NOMBRE DE CADA FILA:") | ||
for index, row in df.iterrows(): | ||
print(index, row['Name']) | ||
|
||
# POKEMONS DE TIPO 1 == WATER | ||
print("\nPOKEMONS DE TIPO 1 == WATER:") | ||
print(df[df['Type 1'] == 'Water']) | ||
|
||
# ESTADÍSTICAS (usando Describe del DataFrame) | ||
print("\nESTADÍSTICAS:") | ||
print(df.describe()) | ||
|
||
# ORDENACIÓN POR NOMBRE ASCENDENTE | ||
print("\nORDENACIÓN POR NOMBRE ASCENDENTE:") | ||
print(df.sort_values('Name')) | ||
|
||
# CREAR UNA COLUMNA EXTRA CALCULADA | ||
df['Total'] = df['HP'] + df['Attack'] + df['Defense'] + df['Speed'] | ||
print("\nCON COLUMNA TOTAL:") | ||
print(df) | ||
|
||
# ELIMINAR LA COLUMNA TOTAL | ||
df = df.drop(columns=['Total']) | ||
print("\nSIN COLUMNA TOTAL:") | ||
print(df) | ||
|
||
# FILTRAR POKEMONS DE TIPOS "GRASS" Y "POISON" | ||
print("\nPOKEMONS DE TIPOS 'GRASS' Y 'POISON':") | ||
print(df[(df['Type 1'] == 'Grass') & (df['Type 2'] == 'Poison')]) | ||
|
||
# FILTRAR POKEMONS DE TIPO "FIRE" Ó "POISON" | ||
print("\nPOKEMONS DE TIPO 'FIRE' Ó 'POISON':") | ||
print(df[(df['Type 1'] == 'Fire') | (df['Type 2'] == 'Poison')]) | ||
|
||
# FILTRAR POKEMONS DE TIPO "GRASS" Y "POISON" Y UN HP >= 70 | ||
print("\nPOKEMONS DE TIPO 'GRASS' Y 'POISON' Y UN HP >= 70:") | ||
print(df[(df['Type 1'] == 'Grass') & (df['Type 2'] == 'Poison') & (df['HP'] >= 70)]) | ||
|
||
# FILTRAR POKEMONS CON NOMBRE "MEGA" | ||
print("\nPOKEMONS CON NOMBRE 'MEGA':") | ||
print(df[df['Name'].str.contains('Mega')]) | ||
|
||
# FILTRAR POKEMONS SIN NOMBRE "MEGA" | ||
print("\nPOKEMONS SIN NOMBRE 'MEGA':") | ||
print(df[~df['Name'].str.contains('Mega')]) | ||
|
||
# FILTRAR POKEMONS CUYOS NOMBRES COMIENCEN CON "PI" | ||
print("\nPOKEMONS CUYOS NOMBRES COMIENCEN CON 'PI':") | ||
print(df[df['Name'].str.startswith('Pi')]) | ||
|
||
# RENOMBRADO DE COLUMNA "FIRE" a "FLAME" | ||
df.rename(columns={'Type 1': 'Flame'}, inplace=True) | ||
print("\nRENOMBRADO DE 'Type 1' A 'Flame':") | ||
print(df) | ||
|
||
# RENOMBRAR DE NUEVO A "FIRE" LA COLUMNA "FLAME" RECIÉN CAMBIADA | ||
df.rename(columns={'Flame': 'Type 1'}, inplace=True) | ||
print("\nRENOMBRADO DE 'Flame' A 'Type 1':") | ||
print(df) | ||
|
||
# CAMBIAR A TODOS LOS POKEMON LEGENDARIOS A TIPO "FIRE" | ||
df.loc[df['Legendary'] == True, 'Type 1'] = 'Fire' | ||
print("\nCAMBIAR A TODOS LOS POKEMON LEGENDARIOS A TIPO 'FIRE':") | ||
print(df) | ||
|
||
# (Agrupación - groupBy) ESTADÍSTICAS DE MEDIA POR TIPO DE POKEMON y ORDENADOS POR DEFENSA | ||
print("\nESTADÍSTICAS DE MEDIA POR TIPO DE POKEMON ORDENADOS POR DEFENSA:") | ||
print(df.groupby('Type 1').mean(numeric_only=True).sort_values('Defense')) | ||
|
||
# (Agrupación - groupBy) ESTADÍSTICAS DE MEDIA POR TIPO DE POKEMON y ORDENADOS POR ATAQUE | ||
print("\nESTADÍSTICAS DE MEDIA POR TIPO DE POKEMON ORDENADOS POR ATAQUE:") | ||
print(df.groupby('Type 1').mean(numeric_only=True).sort_values('Attack')) | ||
|
||
# (Agrupación - groupBy) ESTADÍSTICAS DE MEDIA POR TIPO DE POKEMON y ORDENADOS POR HP | ||
print("\nESTADÍSTICAS DE MEDIA POR TIPO DE POKEMON ORDENADOS POR HP:") | ||
print(df.groupby('Type 1').mean(numeric_only=True).sort_values('HP')) | ||
|
||
# (Agrupación - groupBy) ESTADÍSTICAS DE SUMA POR TIPO DE POKEMON | ||
print("\nESTADÍSTICAS DE SUMA POR TIPO DE POKEMON:") | ||
print(df.groupby('Type 1').sum(numeric_only=True)) | ||
|
||
# (Agrupación - groupBy) ESTADÍSTICAS DE NÚMERO DE POKEMONS POR TIPO 1 DE POKEMON | ||
print("\nESTADÍSTICAS DE NÚMERO DE POKEMONS POR TIPO 1 DE POKEMON:") | ||
print(df.groupby('Type 1').count()) | ||
|
||
# (Agrupación - groupBy) ESTADÍSTICAS DE NÚMERO DE POKEMONS POR TIPO 1 y 2 DE POKEMON | ||
print("\nESTADÍSTICAS DE NÚMERO DE POKEMONS POR TIPO 1 y 2 DE POKEMON:") | ||
print(df.groupby(['Type 1', 'Type 2']).count()) | ||
|
||
# LEE EL ARCHIVO CVS SEPARÁNDOLO POR CHUNKS Y CON UN TAMAÑO DE (chunksize=5) | ||
print("\nLEER EL ARCHIVO CSV POR CHUNKS (chunksize=5):") | ||
chunk_size = 5 | ||
for chunk in pd.read_csv('pokemon_data.csv', chunksize=chunk_size): | ||
print(chunk) |
File renamed without changes.
45 changes: 45 additions & 0 deletions
45
ALUMNOS/MDAA/ALEX_REVERT/PYTHON/SESION5/EJERCICIO2/ejercicio2.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,45 @@ | ||
class Automovil: | ||
def __init__(self, marca, modelo, año): | ||
self.marca = marca | ||
self.modelo = modelo | ||
self.año = año | ||
self.encendido = False | ||
self.velocidad = 0 | ||
|
||
def arrancar(self): | ||
if not self.encendido: | ||
self.encendido = True | ||
print(f"El automóvil {self.marca} {self.modelo} ha arrancado.") | ||
else: | ||
print(f"El automóvil {self.marca} {self.modelo} ya está encendido.") | ||
|
||
def acelerar(self, incremento): | ||
if self.encendido: | ||
self.velocidad += incremento | ||
print(f"El automóvil {self.marca} {self.modelo} ha acelerado a {self.velocidad} km/h.") | ||
else: | ||
print(f"El automóvil {self.marca} {self.modelo} está apagado. No se puede acelerar.") | ||
|
||
def frenar(self, decremento): | ||
if self.encendido and self.velocidad > 0: | ||
self.velocidad -= decremento | ||
if self.velocidad < 0: | ||
self.velocidad = 0 | ||
print(f"El automóvil {self.marca} {self.modelo} ha frenado a {self.velocidad} km/h.") | ||
else: | ||
print(f"El automóvil {self.marca} {self.modelo} está apagado o ya está detenido.") | ||
|
||
def parar(self): | ||
if self.encendido: | ||
self.encendido = False | ||
self.velocidad = 0 | ||
print(f"El automóvil {self.marca} {self.modelo} se ha detenido.") | ||
else: | ||
print(f"El automóvil {self.marca} {self.modelo} ya está apagado.") | ||
|
||
|
||
auto = Automovil("Toyota", "Corolla", 2020) | ||
auto.arrancar() | ||
auto.acelerar(50) | ||
auto.frenar(20) | ||
auto.parar() |
Oops, something went wrong.