scissors game

Make a rock, paper, scissors game in Python

Make a rock, paper, scissors game in Python

Hello Coder, welcome to the codewithrandom blog. In this article, we create a rock , paper , scissors game using python programmingĀ  with Complete Source Code.

Make a rock, paper, scissors game in Python

what is rock , paper , scissors game ?

Rock Paper Scissors is a popular game played between two people, where each player selects one of three options: rock, paper, or scissors. The winner is determined by the rules that rock beats scissors, scissors beat paper, and paper beats rock.

 

How To Run The Code :

step 1:Ā open any python code Editor.

step 2:Ā Ā Make a python file main.py

step 3:Ā  import random module

step 4:Ā  Copy the code & Past it

step 5:Ā  Run the file main.py and your program will run

How to build a calculator using python

Create Your Own Email Sender App Using Python

 

#program code šŸ‘‡šŸ‘‡šŸ‘‡šŸ‘‡šŸ‘‡šŸ‘‡

# import random module
import random

#Ā printĀ multilineĀ instruction
rock = '''
    _______
---'   ____)
      (_____)
      (_____)
      (____)
---.__(___)
'''

paper = '''
    _______
---'   ____)____
          ______)
          _______)
         _______)
---.__________)
'''

scissors = '''
    _______
---'   ____)____
          ______)
       __________)
      (____)
---.__(___)
'''

game_images = [rock, paper, scissors]

# take the input from user
user_choice = int(input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.\n"))

print(game_images[user_choice])

computer_choice = random.randint(0, 2)
print("Computer chose:")
print(game_images[computer_choice])
#Using an ifelif elseĀ block,Ā youĀ canĀ compareĀ playersā€™Ā choicesĀ andĀ determineĀ aĀ winner: if user_choice >= 3 or user_choice < 0: print("You typed an invalid number, you lose!") elif user_choice == 0 and computer_choice == 2: print("You win!") elif computer_choice == 0 and user_choice == 2: print("You lose") elif computer_choice > user_choice: print("You lose") elif user_choice > computer_choice: print("You win!") elif computer_choice == user_choice: print("It's a draw")

Youā€™ve now written code to take in user input, select a random action for the computer, and decide the winner!

Ā Program Output šŸ‘‡šŸ‘‡šŸ‘‡šŸ‘‡

Make a rock, paper, scissors game in Python

Thanks for following along with this project tutorial. I hope you learned something while making the rock, paper, scissors game in python .

#rock, paper, scissors game



Leave a Reply