forked from mouredev/retos-programacion-2023
-
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
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,27 @@ | ||
""" | ||
/* | ||
* Dada una URL con parámetros, crea una función que obtenga sus valores. | ||
* No se pueden usar operaciones del lenguaje que realicen esta tarea directamente. | ||
* | ||
* Ejemplo: En la url https://retosdeprogramacion.com?year=2023&challenge=0 | ||
* los parámetros serían ["2023", "0"] | ||
*/ | ||
""" | ||
|
||
def url_params(url): | ||
parameters = [] | ||
|
||
url_parameters = url.split("?") | ||
print(url_parameters) | ||
|
||
url_parameters.remove(url_parameters[0]) | ||
url_parameters = "".join(url_parameters).split("&") | ||
print(url_parameters) | ||
|
||
for param,values in enumerate(url_parameters): | ||
for value in values: | ||
if value == "=": | ||
parameters.append(values[values.index(value)+1::]) | ||
print(parameters) | ||
|
||
url_params("https://retosdeprogramacion.com?year=2023&challenge=0") |
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,33 @@ | ||
""" | ||
* Crea una función que sea capaz de detectar si existe un viernes 13 en el mes y el año indicados. | ||
* - La función recibirá el mes y el año y retornará verdadero o falso. | ||
""" | ||
|
||
from datetime import date, time, datetime | ||
|
||
def friday_thirteen(): | ||
""" | ||
This function takes a month and a year and determines if there was a 13 friday. | ||
Args: | ||
month(str): any month | ||
year(str): any year | ||
Returns: | ||
bool: returns if it had been a 13 friday at that date. | ||
""" | ||
month = input("Ingrese un mes (mm): ") | ||
year = input("Ingrese un año (yyyy): ") | ||
|
||
if len(month) == 2 and len(year) == 4: | ||
date_check = datetime.strptime('13'+month+year, '%d%m%Y') | ||
weekday = date_check.weekday() # returns the number of the week day. Starts at monday with '0' | ||
|
||
if weekday == 4: | ||
return True | ||
return False | ||
else: | ||
print("Las fechas no son validas") | ||
|
||
print(friday_thirteen()) |
81 changes: 81 additions & 0 deletions
81
Retos/Reto #13 - ADIVINA LA PALABRA [Media]/python/Paula2409.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,81 @@ | ||
""" | ||
/* | ||
* Crea un pequeño juego que consista en adivinar palabras en un número máximo de intentos: | ||
* - El juego comienza proponiendo una palabra aleatoria incompleta | ||
* - Por ejemplo "m_ur_d_v", y el número de intentos que le quedan | ||
* - El usuario puede introducir únicamente una letra o una palabra (de la misma longitud que | ||
* la palabra a adivinar) | ||
* - Si escribe una letra y acierta, se muestra esa letra en la palabra. Si falla, se resta | ||
* uno al número de intentos | ||
* - Si escribe una resolución y acierta, finaliza el juego, en caso contrario, se resta uno | ||
* al número de intentos | ||
* - Si el contador de intentos llega a 0, el jugador pierde | ||
* - La palabra debe ocultar de forma aleatoria letras, y nunca puede comenzar ocultando más del 60% | ||
* - Puedes utilizar las palabras que quieras y el número de intentos que consideres | ||
*/ | ||
""" | ||
import random | ||
def process_word(): | ||
""" | ||
A word guessing game where the player can guess letters or the | ||
whole word with limited attempts. | ||
Args: | ||
None | ||
Returns: | ||
None | ||
""" | ||
words = ['teclado', 'anteojos','monitor', 'calefactor','edificio','cinturon', | ||
'boligrafo','habitacion','libros','persona','planeta','televisor','telefono','direccion'] | ||
|
||
hidden_letters = [] | ||
new_word_to_guess = word_to_guess = random.choice(words) | ||
quantity_letters_to_hide = int(len(new_word_to_guess)*0.6) | ||
list_positions = [quantity_letters for quantity_letters in range(quantity_letters_to_hide)] | ||
while len(list_positions) != 0: | ||
letter_to_hide = random.randrange(len(new_word_to_guess)) | ||
if letter_to_hide not in hidden_letters: | ||
hidden_letters.append(letter_to_hide) | ||
list_positions.pop() | ||
for position in hidden_letters: | ||
new_word_to_guess = new_word_to_guess.replace(new_word_to_guess[position],"_",1) | ||
return [new_word_to_guess,word_to_guess] | ||
|
||
def guess_word(): | ||
new_word_to_guess = process_word()[0] | ||
word_to_guess = process_word()[1] | ||
intentos = 5 | ||
while intentos != 0: | ||
print("""Escriba la opcion: | ||
1. Adivinar por letra | ||
2. Adivinar por palabra | ||
3. Volver a empezar | ||
4. Salir | ||
""") | ||
option = input() | ||
while option != 4: | ||
if option == 1: | ||
guess = input("Escriba la letra: ") | ||
if guess in word_to_guess: | ||
new_word_to_guess.replace("_",guess) | ||
print(f"La palabra es: {new_word_to_guess}") | ||
else: | ||
print(f"Lo siento. Esa letra no esta en la palabra. La palabra es: {new_word_to_guess}") | ||
intentos -= 1 | ||
elif option == 2: | ||
guess = input("Escriba la palabra: ") | ||
if guess == word_to_guess: | ||
print(f"Bien! La palabra es: {word_to_guess}") | ||
else: | ||
print(f"Lo siento, esa no es la palabra") | ||
intentos -= 1 | ||
elif option == 3: | ||
guess_word() | ||
if "_" not in new_word_to_guess: | ||
print(f"Has adivinado la palabra, es: {new_word_to_guess}") | ||
|
||
print(f"No ha podido adivinar la palabra: {word_to_guess}") | ||
|
||
print(process_word()) | ||
guess_word() |
41 changes: 41 additions & 0 deletions
41
Retos/Reto #14 - OCTAL Y HEXADECIMAL [Fácil]/python/Paula2409.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,41 @@ | ||
""" | ||
/* | ||
* Crea una función que reciba un número decimal y lo trasforme a Octal | ||
* y Hexadecimal. | ||
* - No está permitido usar funciones propias del lenguaje de programación que | ||
* realicen esas operaciones directamente. | ||
*/ | ||
""" | ||
def octal_hexadecimal(number): | ||
table_hexa = {'10':'A', '11':'B', '12':'C', '13':'D', '14':'E', '15':'F'} | ||
number_octal,number_hexa = number,number | ||
result_octal, result_hexa = [],[] | ||
|
||
''' Calculate Octal number''' | ||
while number_octal > 0: | ||
result_octal.append(str(number_octal % 8)) | ||
number_octal = number_octal // 8 | ||
|
||
octal = "".join(result_octal[::-1]) | ||
|
||
''' Another way to return ''' | ||
# for digit in result_octal[::-1]: | ||
# octal += str(digit) | ||
|
||
'''Calculate Hexadecimal number ''' | ||
while number_hexa > 0: | ||
if str(number_hexa % 16) in table_hexa: | ||
result_hexa.append(table_hexa[str(number_hexa % 16)]) | ||
else: | ||
result_hexa.append(str(number_hexa % 16)) | ||
number_hexa = number_hexa // 16 | ||
|
||
hexadecimal = "".join(result_hexa[::-1]) | ||
|
||
if number == 0: | ||
octal,hexadecimal = 0,0 | ||
return f"The number {number} in octal is: {octal} and in hexadecimal is: {hexadecimal}" | ||
|
||
print(octal_hexadecimal(0)) | ||
print(octal_hexadecimal(100)) | ||
print(octal_hexadecimal(1000)) |