Created
November 29, 2017 17:42
-
-
Save adamplabarge/b8ecb80f7b23c7cd24f599aef821fe04 to your computer and use it in GitHub Desktop.
Python Class - Rock Paper Scissors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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