Last active
December 30, 2017 03:49
-
-
Save wynand1004/a0e5c401caaf63c5f1b531cf4a2f66e4 to your computer and use it in GitHub Desktop.
Basic Rock Paper Scissors Program (No Loop)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Janken with Loop Assignment Example by Christian Thompson | |
#Uses Random numbers 1-3 to represent Rock, Paper, Scissors | |
#Initialize | |
import os | |
import random | |
import time | |
#Declare variables | |
os.system("clear") | |
#Show the instructions | |
print("""************************************************************ | |
Welcome to Rock Paper Scissors... | |
The rules are simple: | |
The computer and user choose from Rock, Paper, or Scissors. | |
Rock crushes scissors. | |
Paper covers rock. | |
and | |
Scissors cut paper. | |
You will play the computer...the first to reach 3 wins wins the match. | |
Good luck! | |
************************************************************ | |
""") | |
user_choice = input("Please choose (R) Rock, (P) Paper, or (S) Scissors: ").upper() | |
#Let the computer make a choice | |
#1 = rock | |
#2 = paper | |
#3 = scissors | |
random_number = random.randint(1,3) | |
#Convert random number to R, P, or S for Rock, Paper, Scissors | |
if random_number == 1: | |
computer_choice = "R" | |
elif random_number == 2: | |
computer_choice = "P" | |
elif random_number == 3: | |
computer_choice = "S" | |
#Print ASCII Art for the computer's choice | |
if computer_choice == "R": | |
print(""" | |
_______ | |
---' ____) | |
(_____) | |
(_____) | |
(____) | |
---.__(___) | |
The computer chose rock.""") | |
elif computer_choice == "P": | |
print(""" | |
_______ | |
---' ____)____ | |
______) | |
_______) | |
_______) | |
---.__________) | |
The computer chose paper.""") | |
elif computer_choice == "S": | |
print(""" | |
_______ | |
---' ____)____ | |
______) | |
__________) | |
(____) | |
---.__(___) | |
The computer chose scissors.""") | |
print("") | |
#User wins | |
#Computer: R User: P | |
#Computer: P User: S | |
#Computer: S User: R | |
if (computer_choice == "R" and user_choice == "P") or \ | |
(computer_choice == "P" and user_choice == "S") or \ | |
computer_choice == "S" and user_choice == "R": | |
print("You win!") | |
#Computer wins | |
#Computer: R User: S | |
#Computer: P User: R | |
#Computer: S User: P | |
elif (computer_choice == "R" and user_choice == "S") or \ | |
(computer_choice == "P" and user_choice == "R") or \ | |
(computer_choice == "S" and user_choice == "P"): | |
print("You lose!") | |
#Tie | |
#Computer: R User: R | |
#Computer: P User: P | |
#Computer: S User: S | |
elif computer_choice == user_choice: | |
print("Tie!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment