How to Make a (Rock, Paper, Scissors) Game Using Python Coding!
by Bowski16 in Circuits > Computers
124 Views, 1 Favorites, 0 Comments
How to Make a (Rock, Paper, Scissors) Game Using Python Coding!
I made a (Rock, Paper, Scissors) game. It calculates the number of times the user picked one of (Rock, Paper, Scissors). It also calculates the number of times the Player won, and the number of times the Computer won, also the number of ties between the user and computer.
Also how many times the user picked each (Rock, Paper, Scissors)
Supplies
- Python Compiler ( Just google search one ). I recommended GDB online Debugger. That's the one I used.
- Computer
Look at the pics for the code and zoom in because if you miss a single ":" the whole program won't work ok ;) .
from collection import Counter - This is gonna help us calculate stuff in the future.
import random - We need this so the computer can choose a random option between (Rock, Paper, Scissors)
import time - Is so everything doesn't print right away and the user can read what's going on.
The last two print statements are just titles for the game.
def main(): - This code is just so we can call everything towards the end of the code
number_rock_picked = Is so we can calculate number of times user picks that choice.
number_Paper_picked = Is so we can see how many times user picks paper
number_Scissors_picked = Is so we can calculate how many times the user picked Scissors.
------------------------------------------------------------------------------------------------------------------------------------
rock = 0
paper = 0
scissors = 0
All these three codes are gonna be used to calculate the users future favorite choice, because they are going to go into a list called ( my_list )
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TIE = 0
Computer_Wins = 0
Player_Wins = 0
All these codes are gonna calculate who won and how many ties between the computer and user happened.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
my_list = [ ] - This just creates an empty list named my_list . We are going to store the user's choice and find the most choice.
win_list = [ ] - This creates an empty list named win_list . We are going to store the user's win, computer's wins and the amount of Tie's that happened.
If you look to the left you will see the number 23. Look at number 23 - 33.
What this part does is set a loop. So once the user presses Y it would print the user's options. If the user input's R it would add the value 1 to " number_rock_picked " this is how we calculate the number of times the user selects an option.
It added 1 to " number_ rock_picked " and then added it to a list.
The code that added it to a list was - " my_list.append(choice) "
We called the list " my_list " and the " .append " is the keyword that added things to the list. The " (choice) " is the variable name that is asked the user what option he is going with (Rock, Paper, Scissors) . So his option is gonna be added to the list.
Line: Description:
35 - If you zoom in you will see the code " computer_choice = random.randint(0, 3 ) ". Remember " rock = 0" and " paper = 1 " and "scissors = 2 " .
So the computer is gonna choose between one of these. The number to the right inside of the parentheses " 3 " is actually reference 2 for some reason it just represents 1 number down from it so that's why I put 3.
36 - 60 - This just determines who the winner is.
Line 36 - "R" references rock. So if the user chooses rock and the computer chooses "0" in other words "rock" then it's gonna " print("Computer Choice:Rock") " print the computer's choice which is rock. Then the " time.sleep(1) " just pauses for 1 second and prints it's a TIE.
This code is just the same thing it declares the winner. So make sure every time you press Enter to the next line just keep on riding the code.
Line 83 - 90 - Is just figuring out what favorite choice the user entered and the computer is gonna most likely go the opposite choice to win.
Line 92 - 101 - just ask the user if he wants to play again if so then he'll play again. But if he doesn't and enter 'Q' line 94 -99 will print the result on how many wins the player won and how much wins the computer won. Also how many times he picks each (Rock, Paper, Scissors).
Final Overview of It all Together
Look at how I write it because if you put some things together it won't work right. Thoroughly look through my code because if you so much miss a single " : " the whole code wont work.