How to make Stone Paper and Scissor game in Python

How to make Stone Paper and Scissor game in Python

So, you want a quick project to show off your python skills? Well, this could be a good beginner-level Python project to work on to test your basics and gets hands-on experience in Python programming.

We chose Python because Python is a high-level programming language with an easy to use syntax and various modules built-in.

Well, the game is simple, it is like the traditional Stone, Paper, Scissor game, whichever player got 3 points first wins the game. We used to do it a lot in case of seeking the majority or who will get the batting first, just kidding! Let’s get back to the topic.

So, the code is simple, there are two options:

  • Player1 vs COM
  • Player1 vs Player2

The important part is the COM one, We use a random number to generate a number between 1 to 3, by using the random module.

So, instead of using full phrases like Stone or Paper or Scissor, we will use numbers instead.

  • Stone = 1
  • Paper = 2
  • Scissor = 3

So, users will have to input numbers. Below is the Source code, you can view it is coded by me. So, if you want, feel free to share it with your friends.

# stone, paper, scissor game using Python
# coded with <3 by V01D.


import random                   # importing Random module 
import pyfiglet                 # importing Pyfiglet module

ascii_banner = pyfiglet.figlet_format("Stone , Paper & Scissor GAME ")  # ascii banner using Pyfiglet
print(ascii_banner)





print("\t Welcome to the Game \n")
print(" \tROCK PAPER & SCISSOR ")
print("........................................\n")


player1 = input("Enter your Name: ")
print("\n")


print("Playing Mode: ")
print("1. COM ")
print("2. Player 2 ")
print("\n")


mode = input("Enter your Choice: ")
mode = int(mode)
print("\n")

if(mode==1):                                #  mode 1 Vs COM
    point1=0
    point2=0

    while( point1<3 or point2<3):          # initializing a while loop till 3 points

        st = 1                             # stone = 1 ; stone is represented by 1 
        pa = 2                             # paper = 2 ; paper is represented by 2 
        sc = 3                             # scissor = 3 ; scissor is represented by 3

        chance1 = input("Player1: ")        # asking for input for player1
        chance1 = int(chance1)
        print("\n")

        chance2 = 0                         # making chance2 variable to 0 so that it can become a int 
        chance2=random.randint(1, 3)        # using randint random number from random module with series btw 1 and 3 
        print("Player2: ",chance2)
        
        

    
        
    
        if(chance1==1 and chance2==3 or chance1==1 and chance2==3 or chance1==2 and chance2==1):    # winning condition for player1

            print("\n")
            print("Player1 got one point")
            point1=point1+1
            print("\n")
            
            if(point1==3):                                      # if condition is TRUE ; it will come out of loop
                print("\n")                                  
                print("\t........> Player1 won!!! ........")
                break
        elif(chance1==1 and chance2==1 or chance1==2 and chance2==2 or chance1==3 and chance2==3):
            print("No points won! ; Play Again")
                
        else:
            print("\n")
            print("player2 got one point")
            point2=point2+1
            print("\n") 
              
            if(point2==3):
                print("\n")
                print("\t........> Player2 won!!! ........")
                break   


elif(mode==2):                                # mode 2 vs Player 2
    point1=0
    point2=0

    while( point1<3 or point2<3):          # initializing a while loop till 3 points

        st = 1                             # stone = 1 ; stone is represented by 1 
        pa = 2                             # paper = 2 ; paper is represented by 2 
        sc = 3                             # scissor = 3 ; scissor is represented by 3

        chance1 = input("Player1: ")        # asking for input for player1
        chance1 = int(chance1)
        print("\n")

        chance2 = input("Player2: ")        # asking for input for player 2
        chance2 = int(chance2)
        print("\n")

    
        
    
        if(chance1==1 and chance2==3 or chance1==1 and chance2==3 or chance1==2 and chance2==1):    # winning condition for player1

            print("\n")
            print("Player1 got one point")
            point1=point1+1
            print("\n")
            
            if(point1==3):                                      # if condition is TRUE ; it will come out of loop
                print("\n")                                  
                print("\t........> Player1 won!!! ........")
                break
        else:
            print("\n")
            print("player2 got one point")
            point2=point2+1
            print("\n") 
              
            if(point2==3):
                print("\n")
                print("\t........> Player2 won!!! ........")
                break   






#   Thank You for reading this code. Orginally developed By "V01D" from www.inventyourshit.com
    

Screenshots:

How to make Stone Paper and Scissor game in Python

How to make Stone Paper and Scissor game in Python

How to make Stone Paper and Scissor game in Python

You can download the code file here:

CLICK HERE TO DOWNLOAD

IMPROVEMENTS: Well, It is a small project but we can improve its code surely if you have better code than this, feel free to contact us and get it featured here. Moreover, I was thinking if we can add a speech recognition feature in it to make it play along with some cool hand animations. So that every time, we say stone it does something and the same for others.

CONCLUSION: So, that it is, A beginner-level Python project. To be honest, it doesn’t matter how big it is, I made it because I have to test my basics, and I did without any help. So, just do what you feel like, Coding gives you the power to make anything you want. So till then “Happy Coding”.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top