import random def play_game(player_choice): computer_choice = random.choice(['r', 'p', 's']) if player_choice == computer_choice: print('The computer chose the same thing! It\'s a tie!') elif (ord(player_choice) - ord('r') + 1) % 3 == ord(computer_choice) - ord('r'): print('The computer wins this round!') else: print('You win this round!') print("Let's play a game of rock-paper-scissors!") player_wins = 0 computer_wins = 0 while True: player_choice = input("choose [r]ock, [p]aper or [s]cissors: ").lower() if player_choice == "r": print(f"player chose rock") computer_choice = random.choice(['r', 'p', 's']) if computer_choice == 'r': print('The computer chose rock too! It\'s a tie!') elif computer_choice == 'p': print('The computer chose paper! You lose this round.') computer_wins += 1 else: print('The computer chose scissors! You win this round.') player_wins += 1 elif player_choice in ['p', 'paper']: play_game(player_choice) if player_choice == computer_choice: print('It\'s a tie!') elif (ord(player_choice) - ord('r') + 1) % 3 == ord(computer_choice) - ord('r'): print('The computer wins this round!') computer_wins += 1 else: print('You win this round!') player_wins += 1 else: print('Invalid choice! Please choose either r (for rock), p (for paper) or s (for scissors).') play_again = input("Do you want to play again? (yes/no): ").lower() if play_again != 'yes': break print(f"Player wins: {player_wins}, Computer wins: {computer_wins}") if player_wins > computer_wins: print("Congratulations, you won the game!") elif player_wins < computer_wins: print("Sorry, the computer won the game!") else: print("It's a tie game!")