Rock, Paper, Scissors
In this video, I guide you step-by-step on how to create a fun and entertaining Rock-Paper-Scissors game in Python! The code is below. Hope you like it!
from random import randint # Importing libraries
lst = ["Rock", "Paper", "Scissors"] # Make a list that contains all the Rock-Paper-Scissors moves for the computer
computer = lst[randint(0,2)] # Tell the computer to pick a random move from the moves list
player = False # Set player's turn to false(Now it is the computer's turn)
while player == False: # A while loop that defines what happens in the computer's turn
player = input("Rock, Paper, Scissors, Quit?") # Ask the player for their move
if player == computer: # If the player's move is the same as the computer's move, then nobody wins
print("Tie!")
if player == 'Quit': # If the player types in "Quit", then stop the running loop
print('Thanks for playing!')
break # Keyword in Python that means stop running the loop
elif player == "Rock": # If the player types in "Rock" and the computer picks "Paper", the player loses
if computer == "Paper":
print("You lose!", computer, "covers", player)
else:
print("You win!", player, "smashes", computer) # Otherwise, the player wins
elif player == "Paper": # If the player types in "Paper" and the computer picks "Scissors", the computer wins
if computer == "Scissors":
print("You lose!", computer, "cut", player)
else:
print("You win!", player, "covers", computer) # Otherwise, the computer loses
elif player == "Scissors": # If the player types in "Scissors", and the computer picks "Rock", the computer wins
if computer == "Rock":
print("You lose...", computer, "smashes", player)
else:
print("You win!", player, "cut", computer) # Otherwise, the computer loses
else:
print("That's not a valid play. Check your spelling!") # If player types in anything else besides the valid moves, then display error message
player = False # Set player's turn to false(Now computer's turn)
computer = lst[randint(0,2)] # Tell the computer to pick a random move from the moves list