Rock Paper Scissors Game using Python
The objective of the rock-paper-scissor python project is to build a game for a single player that plays with a computer, anywhere, and anytime.
Python is a multi-purpose language and can be used do anything. Hence, it can also be used for game development.
Let’s create a simple command-line Rock-Paper-Scissor game without using any external game libraries like PyGame. In this game, the user gets the first chance to pick the option between Rock, paper, and scissors. After the computer select from the remaining two choices(randomly), the winner is decided as per the rules.
- Rock smashes scissors.
- Paper covers rock.
- Scissors cut paper.
Output:
Enter a choice (rock, paper, scissors): rockYou chose rock, computer chose rock.Both players selected rock. It's a tie!
In-case you want to multiple games at one time, let’s add the option to retry:
We use an endless while loop with the condition to check at the bottom whether we want to continue playing or not, if the user says no then the loop simply ends.
Here is the code implementation:
Output:
Conclusion
Congratulations! You just finished your first Python game! You now know how to create rock paper scissors from scratch.
In this tutorial, you learned how to:
- Code your own rock paper scissors game
- Take in user input with
input()
- Play several games in a row using a
while
loop
These short programs will continue to help you throughout your many programming adventures. If you have any questions, then feel free to reach out in the comments section below.
If you enjoyed this post…it would mean a lot to me if you could click on the “claps” icon…up to 50 claps allowed — Thank You!