import random # Checks that the user enters a valid number of rounds def int_check(question): while True: to_check = input(question) # Infinite mode if to_check == "": return "infinite" try: response = int(to_check) if response < 1: print("Please enter a number that is 1 or greater.") else: return response except ValueError: print("Please enter a valid number.") # Checks player's choice def choice_check(): valid_choices = { "r": "rock", "p": "paper", "s": "scissors", "rock": "rock", "paper": "paper", "scissors": "scissors", "xxx": "xxx" } while True: choice = input("Choose Rock (R), Paper (P), or Scissors (S): ").lower() if choice in valid_choices: return valid_choices[choice] print("Please enter R, P, S, Rock, Paper, or Scissors.") # Main Routine Starts Here mode = "regular" rounds_played = 0 player_wins = 0 computer_wins = 0 draws = 0 choices = ["rock", "paper", "scissors"] print("šŸŽ® Rock Paper Scissors šŸŽ®") print() # Ask for number of rounds num_rounds = int_check( "How many rounds would you like? Press for infinite mode: " ) if num_rounds == "infinite": mode = "infinite" num_rounds = 5 # Game Loop while rounds_played < num_rounds: if mode == "infinite": heading = f"\n--- Round {rounds_played + 1} (Infinite Mode) ---" else: heading = f"\n--- Round {rounds_played + 1} of {num_rounds} ---" print(heading) player_choice = choice_check() # Exit code if player_choice == "xxx": break computer_choice = random.choice(choices) print(f"You chose: {player_choice}") print(f"Computer chose: {computer_choice}") # Determine winner if player_choice == computer_choice: print("It's a draw!") draws += 1 elif ( (player_choice == "rock" and computer_choice == "scissors") or (player_choice == "paper" and computer_choice == "rock") or (player_choice == "scissors" and computer_choice == "paper") ): print("You win!") player_wins += 1 else: print("Computer wins!") computer_wins += 1 rounds_played += 1 # Increase rounds in infinite mode if mode == "infinite": num_rounds += 1 # End of Game Statistics print("\nšŸŽÆ Game Over") print(f"Rounds Played: {rounds_played}") print(f"Player Wins: {player_wins}") print(f"Computer Wins: {computer_wins}") print(f"Draws: {draws}") if player_wins > computer_wins: print("Overall Winner: Player") elif computer_wins > player_wins: print("Overall Winner: Computer") else: print("Overall Result: Draw")