-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6301 from Majinka10/main
Reto #47 - Python
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [Fácil]/python/majinka10.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,40 @@ | ||
# En esta parte del código creo el diccionario utilizando | ||
# codigo ASCII y enumerando cada letra para asignarle el valor | ||
|
||
diccionario = {} | ||
|
||
for i, code in enumerate(range(65, 91)): | ||
if i+1 < 15: | ||
diccionario[chr(code)] = i+1 | ||
else: | ||
diccionario[chr(code)] = i+2 | ||
else: | ||
diccionario[chr(209)] = 15 # Else para añadir la Ñ | ||
|
||
# Funcion para calcular los puntos de la palabra | ||
def puntos_palabra(diccionario: dict, palabra: str) -> int: | ||
valor = 0 | ||
for letra in palabra: | ||
valor += diccionario[letra.upper()] | ||
return valor | ||
|
||
# Funcion para obligar al usuario a introducir una palabra. | ||
def leer_palabra(): | ||
while True: | ||
entrada = input("Introduce una palabra\n") | ||
if entrada.isalpha() and len(entrada) > 0: | ||
return entrada | ||
else: | ||
print("La entrada debe ser una palabra.") | ||
|
||
# Funcion para encontrar una palabra con 100 puntos. | ||
def onehundred_word(): | ||
palabra = leer_palabra() | ||
valor = puntos_palabra(diccionario, palabra) | ||
if valor != 100: | ||
print(f'Esta palabra tiene {valor} puntos!') | ||
return onehundred_word() | ||
else: | ||
return 'Felicitaciones!. Encontraste una palabra de 100 puntos.' | ||
|
||
print(onehundred_word()) |