Rock, paper, scissor game using python

Published on . Written by

Rock, papaer, scissor game using python

Python is a multi-purpose language which can be used to do anything. You can also develop games using python. In this python project, we are going to develop a Rock, paper, scissor game using python. Rock, paper, scissor is a game which is played between two individuals. Here you are going to develop a game where your opponent is the computer. We are not going to use any external library to develop this game.

Read more..

SLNOTE

Skyfi Labs Projects
Project Implementation:

First, import the randint() from the random module.

randint() - It is a function which generates random integers from the given range.

from random import randint

Now, we will create the play options. Rock, Paper, scissor are the play options that you and the computer make on each turn.

t = [“Rock, “Paper”, “Scissor”]

Setup the players (computer and you)

Let’s assign a random play to the computer with the help of randint function, list and t

computer = t[randint(0,2)]

Set the player to False

player = False

Let’s write the actual program where we will create the scenes for all the probabilities such as rock-paper, paper-scissor, scissor-rock, and vice versa for all the three probabilities.

Now, we will look into the while loop. While loop is used in a programming language which allows the code to be executed continuously based on the given condition.

while player == False:

When the loop starts the computer waits for your turn to play. When you start playing, your status changes from False to True. Since the value is assigned to the variable makes the player True.

player = input(“Rock, Paper, Scissor?”)

if player == computer:

print("Tie!")

If the player input and the computer input are the same, the output is a tie.


SLLATEST
elif player == "Rock":

if computer == "Paper":

If the player input is “rock” and computer’s input is “Paper”, the output will be the following

print("You lose!", computer, "covers", player)

else:

            print("You win!", player, "smashes", computer)

Otherwise, it will display the above line.

elif player == "Paper":

        if computer == "Scissors":

            print("You lose!", computer, "cut", player)

        else:

            print("You win!", player, "covers", computer)

If the player chooses paper and computer choose scissor it will display player as looser and computer as the winner. Else it will print player as winner and computer as loose.

elif player == "Scissors":

        if computer == "Rock":

            print("You lose...", computer, "smashes", player)

        else:

            print("You win!", player, "cut", computer)

Here the player input is scissor and the computer input is rock so the result is lost for the player and win for the computer.

If the input is opposite it will reverse the results.

else:

        print("That's not a valid play. Check your spelling!")

If the given input is not there in the list means it will print the above.

player = False

    computer = t[randint(0,2)]

Player was set into False to continue with the loop.

The code for the Rock, paper, scissor, python game is finished. You can compile the code using the python interpreter. Let me know your thoughts about this project in the comment section.


SLDYK
Kit required to develop Rock, paper, scissor game using python:
Technologies you will learn by working on Rock, paper, scissor game using python:


Any Questions?


Subscribe for more project ideas