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 #6104

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
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,37 @@
"""
Crea un programa que calcule los puntos de una palabra.
- Cada letra tiene un valor asignado. Por ejemplo, en el abecedario
español de 27 letras, la A vale 1 y la Z 27.
- El programa muestra el valor de los puntos de cada palabra introducida.
- El programa finaliza si logras introducir una palabra de 100 puntos.
- Puedes usar la terminal para interactuar con el usuario y solicitarle
cada palabra.
"""

from unidecode import unidecode

alphabet = []
for i in range(97, 123):
alphabet.append(chr(i))

alphabet.insert(alphabet.index("n") + 1 ,"ñ")


while True:

word = input("Introduce una palabra: ")

unicode_word = unidecode(word.lower().replace(
"ñ", "_$_")).replace("_$_", "ñ")

value = 0

for letter in unicode_word:
if letter in alphabet:
value += alphabet.index(letter) + 1

print(f"El valor de '{word}' es '{value}'")

if value == 100:
print("Has introducido una palabra de 100! El programa finalizara.")
break
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Crea un programa que calcule quien gana mas partidas al piedra,
papel, tijera, lagartija, spock.
- El resultado puede ser: "Player 1", "Player 2", "Tie" (empate)
- La funcion recibe un listado que contiene pares,
representando cada jugada.
- El par puede contener combinaciones de "🗿" (piedra), "📄"
(papel),
"✂️" (tijera), "🦎" (lagarto) o "🖖" (spock).
- Ejemplo. Entrada: [("🗿","✂️"), ("✂️","🗿"), ("📄","✂️")].
Resultado: "Player 2".
"""

def rpsls(games):

rules = {"🗿": ["✂️", "🦎"],
"📄": ["🗿", "🖖"],
"✂️": ["📄", "🦎"],
"🦎": ["🖖", "📄"],
"🖖": ["🗿", "✂️"]}


player_one = 0
player_two = 0

for game in games:
player_one_game = game[0]
player_two_game = game[1]
if player_one_game != player_two_game:
if player_two_game in rules[player_one_game]:
player_one += 1
else:
player_two += 1
return "Tie" if player_one_game == player_two_game else "Player1" if player_one_game > player_two_game else "Player 2"


print(rpsls([("🗿", "🗿")]))
print(rpsls([("🗿", "✂️")]))
print(rpsls([("✂️", "🗿")]))
print(rpsls(
[("🗿", "🗿"), ("🗿", "🗿"), ("🗿", "🗿"), ("🗿", "🗿")]))
print(rpsls(
[("🖖", "🗿"), ("✂️", "📄"), ("🗿", "🗿"), ("🦎", "🖖")]))