Chat Gpt Build Rock-Paper-Scissors Game in Python

Rock-paper-scissors is a classic hand game played by two people. The game is also known as Roshambo.

In the game, each player chooses one of three options: rock, paper, or scissors. The winner is determined by the following rules:

  • Rock beats scissors (rock crushes scissors)
  • Scissors beats paper (scissors cut paper)
  • Paper beats rock (paper covers rock)

If both players choose the same option, the game is a tie.

The goal of the game is to be the first player to reach 3 points. The player can earn a point by winning a round or by the other player making an invalid choice.

import random


def main():
  # Initialize variables
  choices = ['rock', 'paper', 'scissors']
  player_score = 0
  computer_score = 0

  while player_score < 3 and computer_score < 3:
    # Get player's choice
    player = input('Enter your choice (rock/paper/scissors): ')

    # Validate player's choice
    if player not in choices:
      print('Invalid choice')
      continue

    # Get computer's choice
    computer = random.choice(choices)

    # Determine the winner
    if player == computer:
      print('It\'s a tie!')
    elif player == 'rock' and computer == 'scissors':
      print('You win!')
      player_score += 1
    elif player == 'paper' and computer == 'rock':
      print('You win!')
      player_score += 1
    elif player == 'scissors' and computer == 'paper':
      print('You win!')
      player_score += 1
    else:
      print('Computer wins!')
      computer_score += 1

    # Print the score
    print(f'Score: You {player_score} - Computer {computer_score}')

  # Print the final result
  if player_score == 3:
    print('You won the game!')
  else:
    print('Computer won the game.')

if __name__ == '__main__':
  main()

Leave a Reply

For News Subscribe Us!

Can curiosity may end shameless explained. True high on said mr on come. An do mr design at little myself wholly entire though. Attended of on stronger or mr pleasure.

You have been successfully Subscribed! Ops! Something went wrong, please try again.

© 2022 Code With AM