Saurav Jain (Open Source + Communities) Profile picture
Senior Developer Community Manager @Apify โ€ข Actor Development Advocate โ€ขOpen Sourceโ€ข Web Scrapingโ€ข AI โ€ข Python โ€ข JavaScript โ€ขGitHub โ€ข @Docker Captain

Jul 9, 2021, 9 tweets

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.

Keep scrolling