Skip to content

Instantly share code, notes, and snippets.

@mightywombat
Last active April 23, 2018 23:12
Show Gist options
  • Save mightywombat/ad212d54b6340122542ce4ea52acf518 to your computer and use it in GitHub Desktop.
Save mightywombat/ad212d54b6340122542ce4ea52acf518 to your computer and use it in GitHub Desktop.
practicepython.org Ex 08
# practicepython.org Ex 08
import getpass as g
import string
def crush(word): # Removes all variables from input text for maximum ease of parsing.
word = word.replace(" ", "") # Removes spaces.
word = string.lower(word) # Changes all letters to lowercase.
for c in word:
if c in string.punctuation:
word = word.replace(c, "") # Removes punctuation.
return word
choices = ["rock", "paper", "scissors"]
play = 1
while play == 1:
p1 = "null"
p2 = "null"
while p1 not in choices:
p1 = g.getpass("PLAYER ONE" + "\n" + "Rock, Paper, or Scissors? Choose! ")
p1 = crush(p1)
print ("\n")
while p2 not in choices:
p2 = g.getpass("PLAYER TWO" + "\n" + "Rock, Paper, or Scissors? Choose! ")
p2 = crush(p2)
print ("\n")
# This is the part that decides who wins. Works pretty obvy.
while p1 == "rock":
if p2 == "rock":
print ("It's a TIE! You're both losers.")
if p2 == "paper":
print ("Paper hugs rock! Player Two wins!")
if p2 == "scissors":
print ("Rock smashes Scissors! Player One wins!")
p1 = "null"
while p1 == "paper":
if p2 == "rock":
print ("Paper hugs rock! Player One wins!")
if p2 == "paper":
print ("It's a TIE! You're both losers.")
if p2 == "scissors":
print ("Scissors cut Paper! Player Two wins!")
p1 = "null"
while p1 == "scissors":
if p2 == "rock":
print ("Rock smashes Scissors! Player Two wins!")
if p2 == "paper":
print ("Scissors cut Paper! Player One wins!")
if p2 == "scissors":
print ("It's a TIE! You're both losers.")
p1 = "null"
if raw_input("Do you want to play another round? (y/n)") == "n":
play = 0
# End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment