Skip to content

Instantly share code, notes, and snippets.

@benhosmer
Created April 28, 2012 19:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benhosmer/2521596 to your computer and use it in GitHub Desktop.
Save benhosmer/2521596 to your computer and use it in GitHub Desktop.
Rock, Paper, Scissors - In Python!
# if not re.match("^[a-z]*$", input_str):
import random
import os
import re
os.system('cls' if os.name=='nt' else 'clear')
while (1 < 2):
print "\n"
print "Rock, Paper, Scissors - Shoot!"
userChoice = raw_input("Choose your weapon [R]ock], [P]aper, or [S]cissors: ")
if not re.match("[SsRrPp]", userChoice):
print "Please choose a letter:"
print "[R]ock, [S]cissors or [P]aper."
continue
# Echo the user's choice
print "You chose: " + userChoice
choices = ['R', 'P', 'S']
opponenetChoice = random.choice(choices)
print "I chose: " + opponenetChoice
if opponenetChoice == str.upper(userChoice):
print "Tie! "
#if opponenetChoice == str("R") and str.upper(userChoice) == "P"
elif opponenetChoice == 'R' and userChoice.upper() == 'S':
print "Scissors beats rock, I win! "
continue
elif opponenetChoice == 'S' and userChoice.upper() == 'P':
print "Scissors beats paper! I win! "
continue
elif opponenetChoice == 'P' and userChoice.upper() == 'R':
print "Paper beat rock, I win! "
continue
else:
print "You win!"
@Avishekp6460
Copy link

its showing error in print "\n"

@benhosmer
Copy link
Author

its showing error in print "\n"

Try using Python 2.X

@Avishekp6460
Copy link

?

@benhosmer
Copy link
Author

?

??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment