Advent of code 2
unknown
python
3 years ago
1.4 kB
9
Indexable
def total_score(strategy_guide): # Create a variable to store the total score total_score = 0 # Create a dictionary to store the rules of rock-paper-scissors rules = { "A": "Rock", "B": "Paper", "C": "Scissors" } # Iterate through each round in the strategy guide for round in strategy_guide: # Get the choices for the current round player1_choice = round[0] player2_choice = round[1] # If player 1 chooses rock and player 2 chooses scissors, player 1 wins if rules[player1_choice] == "Rock" and rules[player2_choice] == "Scissors": total_score += 2 # If player 1 chooses paper and player 2 chooses rock, player 1 wins elif rules[player1_choice] == "Paper" and rules[player2_choice] == "Rock": total_score += 2 # If player 1 chooses scissors and player 2 chooses paper, player 1 wins elif rules[player1_choice] == "Scissors" and rules[player2_choice] == "Paper": total_score += 2 # If the choices are the same, it's a draw and no points are awarded else: total_score += 0 # Return the total score return total_score # Test the function with the example strategy guide strategy_guide = [ ("A", "Y"), ("B", "X"), ("C", "Z") ] print(total_score(strategy_guide)) # should print 15
Editor is loading...