├── README.md └── Rock paper scissors /README.md: -------------------------------------------------------------------------------- 1 | class RockPaperScissorsGame: 2 | def __init__(self): 3 | self.user_score = 0 4 | self.computer_score = 0 5 | self.choices = ['rock', 'paper', 'scissors'] 6 | self.computer_choice_index = 0 7 | 8 | def get_computer_choice(self): 9 | choice = self.choices[self.computer_choice_index] 10 | self.computer_choice_index = (self.computer_choice_index + 1) % len(self.choices) 11 | return choice 12 | 13 | def determine_winner(self, user_choice, computer_choice): 14 | if user_choice == computer_choice: 15 | return 'draw' 16 | elif (user_choice == 'rock' and computer_choice == 'scissors') or \ 17 | (user_choice == 'paper' and computer_choice == 'rock') or \ 18 | (user_choice == 'scissors' and computer_choice == 'paper'): 19 | return 'user' 20 | else: 21 | return 'computer' 22 | 23 | def play_round(self): 24 | user_choice = input("Enter your choice (rock, paper, or scissors): ").lower() 25 | while user_choice not in self.choices: 26 | print("Invalid choice. Please try again.") 27 | user_choice = input("Enter your choice (rock, paper, or scissors): ").lower() 28 | 29 | computer_choice = self.get_computer_choice() 30 | print(f"Computer chose: {computer_choice}") 31 | 32 | winner = self.determine_winner(user_choice, computer_choice) 33 | if winner == 'user': 34 | print("You win this round!") 35 | self.user_score += 1 36 | elif winner == 'computer': 37 | print("Computer wins this round!") 38 | self.computer_score += 1 39 | else: 40 | print("This round is a draw!") 41 | 42 | def display_scores(self): 43 | print(f"User Score: {self.user_score} | Computer Score: {self.computer_score}") 44 | 45 | def play_game(self): 46 | print("Welcome to Rock-Paper-Scissors Game!") 47 | while True: 48 | self.play_round() 49 | self.display_scores() 50 | play_again = input("Do you want to play again? (yes/no): ").lower() 51 | if play_again != 'yes': 52 | break 53 | print("Thanks for playing! Final scores:") 54 | self.display_scores() 55 | 56 | if __name__ == "__main__": 57 | game = RockPaperScissorsGame() 58 | game.play_game() 59 | -------------------------------------------------------------------------------- /Rock paper scissors: -------------------------------------------------------------------------------- 1 | class RockPaperScissorsGame: 2 | def __init__(self): 3 | self.user_score = 0 4 | self.computer_score = 0 5 | self.choices = ['rock', 'paper', 'scissors'] 6 | self.computer_choice_index = 0 7 | 8 | def get_computer_choice(self): 9 | choice = self.choices[self.computer_choice_index] 10 | self.computer_choice_index = (self.computer_choice_index + 1) % len(self.choices) 11 | return choice 12 | 13 | def determine_winner(self, user_choice, computer_choice): 14 | if user_choice == computer_choice: 15 | return 'draw' 16 | elif (user_choice == 'rock' and computer_choice == 'scissors') or \ 17 | (user_choice == 'paper' and computer_choice == 'rock') or \ 18 | (user_choice == 'scissors' and computer_choice == 'paper'): 19 | return 'user' 20 | else: 21 | return 'computer' 22 | 23 | def play_round(self): 24 | user_choice = input("Enter your choice (rock, paper, or scissors): ").lower() 25 | while user_choice not in self.choices: 26 | print("Invalid choice. Please try again.") 27 | user_choice = input("Enter your choice (rock, paper, or scissors): ").lower() 28 | 29 | computer_choice = self.get_computer_choice() 30 | print(f"Computer chose: {computer_choice}") 31 | 32 | winner = self.determine_winner(user_choice, computer_choice) 33 | if winner == 'user': 34 | print("You win this round!") 35 | self.user_score += 1 36 | elif winner == 'computer': 37 | print("Computer wins this round!") 38 | self.computer_score += 1 39 | else: 40 | print("This round is a draw!") 41 | 42 | def display_scores(self): 43 | print(f"User Score: {self.user_score} | Computer Score: {self.computer_score}") 44 | 45 | def play_game(self): 46 | print("Welcome to Rock-Paper-Scissors Game!") 47 | while True: 48 | self.play_round() 49 | self.display_scores() 50 | play_again = input("Do you want to play again? (yes/no): ").lower() 51 | if play_again != 'yes': 52 | break 53 | print("Thanks for playing! Final scores:") 54 | self.display_scores() 55 | 56 | if __name__ == "__main__": 57 | game = RockPaperScissorsGame() 58 | game.play_game() 59 | --------------------------------------------------------------------------------