Skip to content

Commit 9de0fcc

Browse files
authored
Merge pull request mouredev#7664 from victorfer69/main
#15 - Python
2 parents 9228233 + a5883aa commit 9de0fcc

File tree

5 files changed

+249
-0
lines changed

5 files changed

+249
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import datetime
2+
import time
3+
import asyncio
4+
5+
#Ejercicio
6+
7+
async def task(name:str, duration:int):
8+
print(f"Tarea: {name}. Duración: {duration}s. Inicio: {datetime.datetime.now()}")
9+
await asyncio.sleep(duration)
10+
print(f"Fin {name}: {datetime.datetime.now()}")
11+
12+
#asyncio.run(task("1", 3))
13+
#asyncio.run(task("2", 2))
14+
15+
16+
#EJERCICIO EXTRA
17+
18+
async def async_tasks():
19+
await asyncio.gather(task("C", 3), task("B", 2), task("A", 1))
20+
await task("D", 1)
21+
22+
asyncio.run(async_tasks())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import re
2+
3+
#Ejercicio
4+
5+
regex = r"\d+"
6+
7+
text = "Este es el ejercicio 16 a fecha del 22 de enero de 2025."
8+
9+
def find_numbers(text:str) -> list:
10+
return re.findall(regex, text)
11+
12+
print(find_numbers(text))
13+
14+
15+
#EJERCICIO EXTRA
16+
17+
def validate_email(email: str) -> bool:
18+
return bool(re.match(r"^[\w.+-]+@[\w]+\.[a-zA-Z]+$", email))
19+
20+
21+
print(validate_email("[email protected]"))
22+
23+
24+
def validate_phone(phone: str) -> bool:
25+
return bool(re.match(r"^\+?[\d\s]{3,}$", phone))
26+
27+
28+
print(validate_phone("+34 901 65 89 044"))
29+
30+
31+
def validate_url(url: str) -> bool:
32+
return bool(re.match(r"^http[s]?://(www.)?[\w]+\.[a-zA-Z]{2,}$", url))
33+
34+
35+
print(validate_url("http://www.moure.dev"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#EJERCICIO
2+
3+
for i in range(1, 11):
4+
print(i)
5+
print("==============")
6+
7+
i = 1
8+
while(i < 11):
9+
print(i)
10+
i += 1
11+
print("==============")
12+
13+
def function_recursive(i:int):
14+
if i == 10:
15+
print(i)
16+
else:
17+
print(i)
18+
i += 1
19+
function_recursive(i)
20+
21+
function_recursive(1)
22+
print("==============")
23+
24+
#EJERCICIO EXTRA
25+
26+
for i in [1, 2, 3]:
27+
print(i)
28+
print("==============")
29+
30+
for i in {1, 2, 3}:
31+
print(i)
32+
print("==============")
33+
34+
for i in {1: "a", 2: "b", 3: "c"}:
35+
print(i)
36+
print("==============")
37+
38+
print(*[i for i in range(1, 11)], sep="\n")
39+
print("==============")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#EJERCICIO
2+
3+
data = [1, 2, 3, 4, 5]
4+
print(data)
5+
6+
#Añade un elemento al principio.
7+
data.append(6)
8+
print(data)
9+
10+
#Añade un elemento en la posicion que quieras
11+
data.insert(0, 0)
12+
print(data)
13+
14+
#Añade varios elementos en bloque al final.
15+
block = [7, 8, 9]
16+
data.extend(block)
17+
print(data)
18+
19+
#Añade varios elementos en bloque en una posición concreta.
20+
data[3:3] = [-1, -2, -3]
21+
print(data)
22+
23+
# Elimina un elemento en una posición concreta.
24+
data.pop(5)
25+
print(data)
26+
27+
# Actualiza el valor de un elemento en una posición concreta.
28+
data[4] = 10
29+
print(data)
30+
31+
# Comprueba si un elemento está en un conjunto.
32+
print(data.__contains__(3))
33+
print(data.__contains__(1234))
34+
35+
# Elimina todo el contenido del conjunto.
36+
data.clear()
37+
print(data)
38+
39+
40+
#EJERCICIO EXTRA
41+
42+
#Union
43+
def union(a, b):
44+
c = []
45+
a.extend(b)
46+
for i in a:
47+
if not c.__contains__(i):
48+
c.append(i)
49+
return c
50+
51+
a = [1, 2, 3, 4, 5]
52+
b = [1, 3, 5, 7, 9]
53+
print(union(a,b))
54+
55+
#Interseccion
56+
def interseccion(a, b):
57+
c = []
58+
for i in a:
59+
if b.__contains__(i):
60+
c.append(i)
61+
return c
62+
63+
a = [1, 2, 3, 4, 5]
64+
b = [1, 3, 5, 7, 9]
65+
print(interseccion(a, b))
66+
67+
#Diferencia
68+
def diferencia(a, b):
69+
c = a
70+
for i in b:
71+
if a.__contains__(i):
72+
c.remove(i)
73+
return c
74+
75+
a = [1, 2, 3, 4, 5]
76+
b = [1, 3, 5, 7, 9]
77+
print(diferencia(a, b))
78+
79+
#Hay operaciones que lo hacen solas
80+
a = {1, 2, 3, 4, 5}
81+
b = {1, 3, 5, 7, 9}
82+
print(f"Unión: {a.union(b)}")
83+
print(f"Intersección: {a.intersection(b)}")
84+
print(f"Diferencia: {a.difference(b)}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from enum import Enum
2+
3+
#EJERCICIO
4+
5+
class Weekday(Enum):
6+
Monday = 1
7+
Tuesday = 2
8+
Wednesday = 3
9+
Thursday = 4
10+
Friday = 5
11+
Saturday = 6
12+
Sunday = 7
13+
14+
def get_day(number:int):
15+
print(Weekday(number).name)
16+
17+
get_day(1)
18+
19+
20+
#EJERCICIO EXTRA
21+
22+
class Estado(Enum):
23+
PENDIENTE = 1
24+
ENVIADO = 2
25+
ENTREGADO = 3
26+
CANCELADO = 4
27+
28+
class order:
29+
30+
def __init__(self, id:int):
31+
self.id = id
32+
self.state = Estado.PENDIENTE
33+
34+
def OrderSended(self):
35+
if self.state == Estado.PENDIENTE:
36+
self.state = Estado.ENVIADO
37+
print("Enviando pedido")
38+
else:
39+
print("El pedido no existe")
40+
41+
def OrderDelivered(self):
42+
if self.state == Estado.ENVIADO:
43+
self.state = Estado.ENTREGADO
44+
print("Pedido entregado")
45+
else:
46+
print("El pedido no esta enviado")
47+
48+
def OrderCancelled(self):
49+
if self.state != Estado.ENTREGADO:
50+
self.state = Estado.CANCELADO
51+
print("Pedido cancelado")
52+
else:
53+
print("El pedido no existe")
54+
55+
def print(self):
56+
print(f"El pedido {self.id}, se encuentra en estado de {self.state.name}.")
57+
58+
order_1 = order(1)
59+
order_1.print()
60+
order_1.OrderSended()
61+
order_1.OrderDelivered()
62+
order_1.print()
63+
64+
65+
order_2 = order(2)
66+
order_2.print()
67+
order_2.OrderSended()
68+
order_2.OrderCancelled()
69+
order_2.print()

0 commit comments

Comments
 (0)