Chat Gpt Build Rock-Paper-Scissors Game in Python

Chat Gpt Build Rock-Paper-Scissors Game in Python

Share It With Your Firends:

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()

Share It With Your Friends

Leave a Reply

Recent Posts

  • All Post
  • A.I.
  • AI
  • c
  • c++
  • computer
  • cryptocurrency
  • database
  • digital marketing
  • finance
  • hacking
  • HTML
  • java
  • Marketing
  • network
  • other
  • programming
  • python
  • react
  • social
  • Tools
  • Uncategorized
  • web devlopment
    •   Back
    • drawing In Python
DIY AI Voice Assistant In Python

September 8, 2023

Build your own AI assistant with Python! Learn to recognize voice commands, generate responses, and more. Create your virtual companion…

share it

Recent Posts

  • All Post
  • A.I.
  • AI
  • c
  • c++
  • computer
  • cryptocurrency
  • database
  • digital marketing
  • finance
  • hacking
  • HTML
  • java
  • Marketing
  • network
  • other
  • programming
  • python
  • react
  • social
  • Tools
  • Uncategorized
  • web devlopment
    •   Back
    • drawing In Python

Additional Content

CodeWithAM

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus luctus.

Products

Automated Chatbot

Data Security

Virtual Reality

Communication

Support

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Codewitham