Skip to content

Commit

Permalink
Merge pull request #3349 from mikelm2020/miguellopezmdev
Browse files Browse the repository at this point in the history
#6-Python
  • Loading branch information
kontroldev authored May 3, 2024
2 parents 84dd7a0 + 4430774 commit 596f8d2
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Roadmap/06 - RECURSIVIDAD/python/mikelm2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Recursividad
# Crea una función recursiva que imprima números del 100 al 0


def numbers(number: int = 100):
if number >= 0:
print(number)
numbers(number - 1)


# Dificultad extra
# Utiliza el concepto de recursividad para:
# Calcular el factorial de un número concreto (la funcion recibe ese número)


def factorial(number: int):
if number == 1:
return 1

if number >= 2:
return number * factorial(number - 1)


# Calcular el valor de un elemento concreto (según su posición) en la
# sucesión de Fibonacci (la función recibe la posición).


def fibonacci(position: int):
if position == 0:
return 0
if position == 1:
return 1
if position >= 2:
return fibonacci(position - 2) + fibonacci(position - 1)


if __name__ == "__main__":
# numbers()
print(factorial(5))
print(fibonacci(15))
96 changes: 96 additions & 0 deletions Roadmap/07 - PILAS Y COLAS/python/mikelm2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# operaciones: introduce - introducir recover - recuperar


class Stack:
def __init__(self):
# Crea una pila vacía
self.items = []

def introduce(self, element):
# Agrega el elemento element a la pila
self.items.append(element)

def recover(self):
# Devuelve el elemento tope y lo elimina
# Si la pila está vacía levanta una excepción
try:
return self.items.pop()
except IndexError:
raise ValueError("La pila está vacía")

def is_empty(self):
# Devuelve True si la pila esta vacía
return self.items == []

def size(self):
return len(self.items)


class Queue:
def __init__(self):
# Crea una cola vacía
self.items = []

def introduce(self, element):
# Agrega el elemento element a la cola
self.items.append(element)

def recover(self):
# Devuelve el primer elemento y lo elimina
# Si la cola está vacía levanta una excepción
try:
return self.items.pop(0)
except IndexError:
raise ValueError("La cola está vacía")

def is_empty(self):
# Devuelve True si la cola esta vacía
return self.items == []


def web_navigation():
navigation = Stack()

while True:
action_of_navigate = input(
"Escribe la URL o las palabras atras, adelante o salir"
)

if action_of_navigate == "adelante":
pass
elif action_of_navigate == "atras":
if not navigation.is_empty():
if navigation.size() > 1:
page = navigation.recover()
else:
page = navigation.items[0]
elif action_of_navigate == "salir":
break
else:
navigation.introduce(action_of_navigate)
page = navigation.items

if not navigation.is_empty():
print(f"Estas en {page}")


def shared_printing():
printing_queue = Queue()

while True:
action = input("Añade un documento o escribe imprimir/salir: ")

if action == "salir":
break
elif action == "imprimir":
if not printing_queue.is_empty():
print(f"Imprimiendo el documento {printing_queue.recover()}")
else:
printing_queue.introduce(action)

print(f"La cola de impresión restante es: {printing_queue.items}")


if __name__ == "__main__":
# web_navigation()
shared_printing()

0 comments on commit 596f8d2

Please sign in to comment.