HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

Python Tutorial 9: Rock Paper Scissors Game

80,848 views November 14, 2019 13:49

Watch on YouTube
Channel10minutetrain

Description from the creator

Python Tutorial 9: Rock Paper Scissors Game. Create a Rock, Paper and Scissors game with Python.

Code:
import random

comp_wins = 0
player_wins = 0

def Choose_Option():
user_choice = input("Choose Rock, Paper or Scissors: ")
if user_choice in ["Rock", "rock", "r", "R"]:
user_choice = "r"
elif user_choice in ["Paper", "paper", "p", "P"]:
user_choice = "p"
elif user_choice in ["Scissors", "scissors", "s", "S"]:
user_choice = "s"
else:
print("I don't understand, try again.")
Choose_Option()
return user_choice

def Computer_Option():
comp_choice = random.randint(1, 3)
if comp_choice == 1:
comp_choice = "r"
elif comp_choice == 2:
comp_choice = "p"
else:
comp_choice = "s"
return comp_choice


while True:
print("")

user_choice = Choose_Option()
comp_choice = Computer_Option()

print("")

if user_choice == "r":
if comp_choice == "r":
print("You chose rock. The computer chose rock. You tied.")

elif comp_choice == "p":
print("You chose rock. The computer chose paper. You lose.")
comp_wins += 1

elif comp_choice == "s":
print("You chose rock. The computer chose scissors. You win.")
player_wins += 1

elif user_choice == "p":
if comp_choice == "r":
print("You chose paper. The computer chose rock. You win.")
player_wins += 1

elif comp_choice == "p":
print("You chose paper. The computer chose paper. You tied.")


elif comp_choice == "s":
print("You chose paper. The computer chose scissors. You lose.")
comp_wins += 1

elif user_choice == "s":
if comp_choice == "r":
print("You chose scissors. The computer chose rock. You lose.")
comp_wins += 1

elif comp_choice == "p":
print("You chose scissors. The computer chose paper. You win.")
player_wins += 1

elif comp_choice == "s":
print("You chose scissors. The computer chose scissors. You tied.")

print("")
print("Player wins: " + str(player_wins))
print("Computer wins: " + str(comp_wins))
print("")

user_choice = input("Do you want to play again? (y/n)")
if user_choice in ["Y", "y", "yes", "Yes"]:
pass
elif user_choice in ["N", "n", "no", "No"]:
break
else:
break

About this tutorial

10minutetrain published this 13:49 video tutorial on November 14, 2019. It has been watched 80,848 times on YouTube.

Category
Education
Duration
13:49
Published
November 14, 2019
Views
80,848
Likes
1,098

Tags

Share

This tutorial in other languages