Game Rules:
If user_1 and user_2 have same choice there is a TIE.
If choices are Paper and Scissors, Scissors wins.
If choices are Paper and Rock, Paper wins.
If choices are Rock and Scissors, Rock wins.
This small project will help you improve your basics such as loops, nested if...else, variables, random module.
So, guys are you ready to create Rock Paper Scissors using Python. So let's start.
First, we will import the Random module in python.
Now, we will use the while loop to take input until the user wants to play.
Let's take input from the user using input() function in python. Then create the computer choice using randint() function from the Random module.
Now, we will convert the computer's input from 1, 2, 3 into 'p', 'r','s'.
Now, compare the user choice with computer choice using nested if...else. And if both choices are same there is a tie.
Now, take input whether the user wants to play again if no then break the loop.
So, that's it you are ready to play. If you enjoyed, do comment. If you have any doubt feel free to ask.
Top comments (1)
Instead of converting you could do this:
computer = random.choice(['r', 'p', 's'])