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.
Python Kit will be shipped to you and you can learn and build using tutorials. You can start for free today!
2. Machine Learning (Career Building Course)
4. Fraud Detection using Machine Learning
5. Machine Learning using Python
6. Movie Recommendation using ML
7. 3 Computer Vision Projects (Combo Course)
8. Computer Vision - Text Scanner
9. Computer Vision Based Mouse
10. Handwritten Digits Recognition using ML
11. Computer Vision Based Smart Selfie
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.
Want to develop practical skills on Python? Checkout our latest projects and start learning for free
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.
Skyfi Labs helps students learn practical skills by building real-world projects.
You can enrol with friends and receive kits at your doorstep
You can learn from experts, build working projects, showcase skills to the world and grab the best jobs.
Get started today!
Join 250,000+ students from 36+ countries & develop practical skills by building projects
Get kits shipped in 24 hours. Build using online tutorials.
Stay up-to-date and build projects on latest technologies