Skip to content

Instantly share code, notes, and snippets.

@adamplabarge
Created November 29, 2017 17:42
Show Gist options
  • Save adamplabarge/b8ecb80f7b23c7cd24f599aef821fe04 to your computer and use it in GitHub Desktop.
Save adamplabarge/b8ecb80f7b23c7cd24f599aef821fe04 to your computer and use it in GitHub Desktop.
Python Class - Rock Paper Scissors
"""
Some python from a free python class offered by The Tech Academy Portland
https://www.meetup.com/techacademy/
"""
import math
from random import randint
randMin = 0
randMax = 2
weaponsList = ('Rock', 'Paper', 'Scissors')
def play():
try:
string = 'Throw! (You can enter: '
for i in range(0, len(weaponsList)):
string += weaponsList[i]
if (i < len(weaponsList)-1):
string += ', '
string += '): '
user = raw_input(string)
print('You showed: ' + user.lower().capitalize())
num = randint(randMin, randMax)
computer = weaponsList[num]
print('I showed: ' + computer)
winner = whoWon(user, computer)
print(winner)
playAgain()
except:
playAgain()
def playAgain():
again = raw_input('Do you want to play again? Yes or No: ')
if again.lower() == 'no':
quit()
elif again.lower() == 'yes':
play()
else:
print('Enter Yes or No: ')
playAgain()
def whoWon(user, computer):
if user.lower() == computer.lower():
return 'Draw'
elif ((user.lower() == 'Rock'.lower()) and (computer == 'Scissors')):
return 'Snap! Your Rock beat my Scissors.'
elif ((user.lower() == 'Paper'.lower()) and (computer == 'Rock')):
return 'Oh shoot! Your flimsy Paper covered my Rock!'
elif ((user.lower() == 'Scissors'.lower()) and (computer == 'Paper')):
return 'I hope you run with those!'
else:
return 'I Won!'
print('Let\'s play some ro sham beaux!')
play()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment