Rock, paper scissors is played between two people, both of them choosing one out of the three options. Then, according to certain rules, one of the two is declared the winner. We will discuss these rules further and moreover, we will implement Rock, Paper, and Scissors in the python programming language.
The randint() function – The randint function is used to generate a random value. The lower and upper limits are passed to this function and the returned value is always between this range. Here, we will pass 1 and 2 because the game has three values. But, to use this function we have to import it from the random module and that is where we will start the program as Step 1 below. And, we will use the function in Step 3 below.
Step 1: Write the code to import random module
Step 2: Take the input from the user – rock or paper or scissors
Step 3: Print the input whatever the user has entered and then start the computer’s turn.
Step 4: Create a random number between 1 and 3 for the computer representing rock, paper, and scissors respectively.
Step 5: Compare the user choice and the computer’s choice and declare the winner.
As a variation of the above game, try to do a game which runs in a loop so that the users can play multiple times and enter “Finish” to close the game.
Learn more about how we teach Python to kids and the details of our Python course for kids and teenagers at UnicMinds. Children will be introduced to Python, a popular programming language. They will learn the fundamentals of Python language and create projects based on the concepts learnt. They’ll work with simple and complex data in this programming environment and will be comfortable coding in Python for various basic applications.
Hope this is useful, thank you.