Skip to content

Instantly share code, notes, and snippets.

@robboggs
Created September 22, 2014 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robboggs/2f85dd29512075bd9a27 to your computer and use it in GitHub Desktop.
Save robboggs/2f85dd29512075bd9a27 to your computer and use it in GitHub Desktop.
Rock, paper, scissor, lizard, spock game for a treehouse.com contest.
import random
# Welcome Message Only shown Once.
print("Welcome to Rock, Paper, Scissors, Lizard, Spock.\nA twist on the game made famous by the\ntv show \'The Big Bang Theory\'.\nOnly use the first letter except for spock. Use the last letter \"k\"\n")
# Function to provide help about what beats what
def help():
print("\nRock crushes Scissors and Lizard\nPaper covers Rock and disproves Spock\nScissors cut Paper and decapitate Lizard\nLizard eats paper and poisons Spock\nSpock vaporizes Rock and crushes Scissors\n")
# Main function. written as function to be called over and over again
def picks():
user_pick = input("Pick: Rock(r) Paper(p) Scissors(s) Lizard(l) or Spock(k)\nInstructions (i) exit (e): ")
user_pick = user_pick.lower()
# This block receives user input and assigns it to their pick
# Use 'k' for spock because wanted to kept it to 1 letter
if user_pick == "r":
user_pick = "Rock"
elif user_pick == "p":
user_pick = "Paper"
elif user_pick == "s":
user_pick = "Scissors"
elif user_pick == "l":
user_pick = "Lizard"
elif user_pick == "k":
user_pick = "Spock"
elif user_pick == "i":
help()
picks()
elif user_pick == "e":
quit()
else:
print ("\nGameplay is smoother if you follow directions.\n")
picks()
# This block creates a random number and assigns it as the opponents pick
opp_num = random.randrange(0,5)
if opp_num == 0:
opp_pick = "Rock"
elif opp_num == 1:
opp_pick = "Paper"
elif opp_num == 2:
opp_pick = "Scissors"
elif opp_num == 3:
opp_pick = "Lizard"
else:
opp_pick = "Spock"
# This block compares user_pick to opp_pick through every possible combination
if user_pick == opp_pick:
print("\nYou both picked " + user_pick + ". It's a draw.\n")
else:
if user_pick == "Rock":
if opp_pick == "Scissors":
print("\n" + user_pick + " crushes " + opp_pick + ", you Win.\n")
elif opp_pick == "Lizard":
print("\n" + user_pick + " crushes " + opp_pick + ", you Win.\n")
elif opp_pick == "Spock":
print("\n" + opp_pick + " vaporizes " + user_pick + ", you Lose.\n")
else:
print("\n" + opp_pick + " covers " + user_pick + ", you Lose.\n")
elif user_pick == "Paper":
if opp_pick == "Rock":
print("\n" + user_pick + " covers " + opp_pick + ", you Win.\n")
elif opp_pick == "Spock":
print("\n" + user_pick + " disproves " + opp_pick + ", you Win.\n")
elif opp_pick =="Lizard":
print("\n" + opp_pick + " eats " + user_pick + ", you Lose.\n")
else:
print("\n" + opp_pick + " cut " + user_pick + ", you Lose.\n")
elif user_pick == "Scissors":
if opp_pick == "Paper":
print("\n" + user_pick + " cut " + opp_pick + ", you Win.\n")
elif opp_pick == "Lizard":
print("\n" + user_pick + " decapitate " + opp_pick + ", you Win.\n")
elif opp_pick =="Spock":
print("\n" + opp_pick + " crushes " + user_pick + ", you Lose.\n")
else:
print("\n" + opp_pick + " crushes " + user_pick + ", you Lose.\n")
elif user_pick == "Lizard":
if opp_pick == "Paper":
print("\n" + user_pick + " eats " + opp_pick + ", you Win.\n")
elif opp_pick == "Spock":
print("\n" + user_pick + " poisons " + opp_pick + ", you Win.\n")
elif opp_pick =="Rock":
print("\n" + opp_pick + " crushes " + user_pick + ", you Lose.\n")
else:
print("\n" + opp_pick + " decapitate " + user_pick + ", you Lose.\n")
else:
if opp_pick == "Rock":
print("\n" + user_pick + " vaporizes " + opp_pick + ", you Win.\n")
elif opp_pick == "Scissors":
print("\n" + user_pick + " crushes " + opp_pick + ", you Win.\n")
elif opp_pick =="Paper":
print("\n" + opp_pick + " disproves " + user_pick + ", you Lose.\n")
else:
print("\n" + opp_pick + " poisons " + user_pick + ", you Lose.\n")
#Goes back to top to keep playing
picks()
# Game begins here by calling function
picks()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment