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

Solución reto#26 Python #1367

Open
grisales54 opened this issue Oct 4, 2024 · 0 comments
Open

Solución reto#26 Python #1367

grisales54 opened this issue Oct 4, 2024 · 0 comments

Comments

@grisales54
Copy link

`juego = [("R", "S"), ("S", "R"), ("P", "S")]

def ganador(juego):
# Contadores para las victorias de cada jugador
player1 = 0
player2 = 0

# Iteramos sobre cada ronda del juego
for i in juego:
    # Comprobamos todas las combinaciones posibles
    # Si el jugador 1 gana, aumentamos su contador
    if i[0] == "P" and i[1] == "R":
        player1 = player1 + 1
    if i[0] == "R" and i[1] == "S":
        player1 = player1 + 1
    if i[0] == "S" and i[1] == "P":
        player1 = player1 + 1

    # Si el jugador 2 gana, aumentamos su contador
    if i[1] == "P" and i[0] == "R":
        player2 = player2 + 1
    if i[1] == "R" and i[0] == "S":
        player2 = player2 + 1
    if i[1] == "S" and i[0] == "P":
        player2 = player2 + 1

# Determinamos el ganador comparando los contadores
if player1 > player2:
    return print("Jugador 1 ganó")
if player2 > player2:  # Nota: Hay un error aquí, debería ser player2 > player1
    return print("Jugador 2 ganó")
if player1 == player2:
    return print("Empate")

Llamamos a la función con nuestro juego de ejemplo

ganador(juego)
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant