Skip to content

Instantly share code, notes, and snippets.

@davidruffner
Last active November 14, 2019 16:05
Show Gist options
  • Save davidruffner/32273f114c1b6dd9399c3e1a91066824 to your computer and use it in GitHub Desktop.
Save davidruffner/32273f114c1b6dd9399c3e1a91066824 to your computer and use it in GitHub Desktop.
Python Exercise: Rock, Paper, Scissors
# A python exercise from [Practice Python](http://www.practicepython.org/exercise/2014/03/26/08-rock-paper-scissors.html).
throwNames = {
0: 'Rock',
1: 'Paper',
2: 'Scissors',
}
def twoPlayerRockPaperScissors():
print 'Welcome to the Rock Paper Scissors game!'
nameP1 = input('Player 1, please enter name:')
nameP2 = input('Player 2, please enter name:')
playAnother = True
while playAnother:
input('Ready? Press any key to play')
throwP1 = input('{}, please enter your throw (Rock 0, Paper 1, or Sciss$
throwP2 = input('{}, please enter your throw (Rock 0, Paper 1, or Sciss$
print throwP1, throwP2
print '{} threw {}, {} threw {}:'.format(nameP1, throwNames[throwP1], n$
throwDiff = throwP1 - throwP2
if throwP1 == throwP2:
print 'It is a tie!'
elif throwDiff in [-2, 1]:
print '{} wins!'.format(nameP1)
else:
print '{} wins!'.format(nameP2)
playAnotherResponse = input('Would you like to play again? If so press $
print repr(playAnotherResponse)
playAnother = playAnotherResponse == 1
print 'Thanks for playing! Goodbye.'
if __name__ == '__main__':
twoPlayerRockPaperScissors()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment