How to make a simple Rock, Paper, Scissor game using Python? โ๐คโ๏ธ
Here in this thread, I will try to make the process easier for you :)
PS - Github link for the project in the last tweet of the thread.
Thread ๐งต๐
๐๐บ๐ฝ๐ผ๐ฟ๐๐ถ๐ป๐ด ๐น๐ถ๐ฏ๐ฟ๐ฎ๐ฟ๐ถ๐ฒ๐
As usual, in every project, the first step is to upload the required libraries for our project
So here we are going to import the random library of python.
Random is widely used to select randomly a choice from all the choices.
๐Code
๐ง๐ฎ๐ธ๐ถ๐ป๐ด ๐ถ๐ป๐ฝ๐๐ ๐ณ๐ฟ๐ผ๐บ ๐๐๐ฒ๐ฟ
So the next step is to taking input from the user.
The possible choices here are rock, paper, scissors.
We will use the input function to do so.
๐Code
๐ ๐ฎ๐ธ๐ฒ ๐ฎ ๐น๐ถ๐๐ ๐ผ๐ณ ๐ฎ๐น๐น ๐ฝ๐ผ๐๐๐ถ๐ฏ๐น๐ฒ ๐ฐ๐ต๐ผ๐ถ๐ฐ๐ฒ๐
The next step is to make a list with all possible choices that are, rock, paper, and scissors.
๐Code
๐๐ต๐ผ๐ผ๐๐ฒ ๐ฎ ๐ฟ๐ฎ๐ป๐ฑ๐ผ๐บ ๐ฐ๐ต๐ผ๐ถ๐ฐ๐ฒ ๐ณ๐ผ๐ฟ ๐ฐ๐ผ๐บ๐ฝ๐๐๐ฒ๐ฟ
So the user had selected the choice and now it's the computer's turn to make a choice.
Here we will use the list made in the previous step with the random.choice function.
๐Code
๐ฃ๐ฟ๐ถ๐ป๐๐ถ๐ป๐ด ๐ฏ๐ผ๐๐ต ๐๐๐ฒ๐ฟ ๐ฎ๐ป๐ฑ ๐ฐ๐ผ๐บ๐ฝ๐๐๐ฒ๐ฟ ๐ฐ๐ต๐ผ๐ถ๐ฐ๐ฒ
This step is completely optional, to print both user and computer choice is totally up to you.
But to make things transparent, I will recommend doing this :P
๐Code
๐๐ผ๐บ๐ฝ๐ฎ๐ฟ๐ถ๐ป๐ด ๐ฎ๐ป๐ฑ ๐๐ฒ๐ป๐ฒ๐ฟ๐ฎ๐๐ถ๐ป๐ด ๐๐ต๐ฒ ๐ฟ๐ฒ๐๐๐น๐
So as we all know the rules-
Tie if both same
Scissors > Paper
Paper > Rock
Rock > Scissors
So we are going to use if-else loop to compare and print the results
๐Code
Hey all,
Hope I am able to make threads from which you are learning something new!!
Here is the link to this project GitHub link -github.com/souravjain540/โฆ
If you like my content, then Retweet the first tweet of this thread :)
Until the next thread, Bye๐
Here you go to the first tweet ๐
RT if you like it !!
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.