Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reto #47 - Python #6301

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())