Created
October 9, 2017 23:31
-
-
Save DuffleOne/7e1516ed24e9f785c24ad11bd75de02d to your computer and use it in GitHub Desktop.
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
import random | |
def tick(humanChoice, computerChoice): | |
if (humanChoice == computerChoice): | |
return { | |
'winner': None, | |
'hScore': 0, | |
'cScore': 0, | |
}; | |
if (humanChoice - computerChoice) % 3 == 1: | |
return { | |
'winner': 'Human', | |
'hScore': 1, | |
'cScore': 0, | |
}; | |
else: | |
return { | |
'winner': 'Computer', | |
'hScore': 0, | |
'cScore': 1, | |
}; | |
def startGame(): | |
loopGame = True; | |
humanScore = 0; | |
computerScore = 0; | |
while loopGame == True: | |
print('type "exit" to exit'); | |
humanChoice = input('Pick rock, paper, or scissors: '); | |
if humanChoice == 'exit': | |
loopGame = False; | |
break; | |
humanNumber = choiceNumber(humanChoice); | |
computerChoice = random.choice([0, 1, 2]); | |
result = tick(humanNumber, computerChoice); | |
humanScore += result['hScore']; | |
computerScore += result['cScore']; | |
print('Computer picked: %s' % numberChoice(computerChoice)); | |
print('Human picked: %s' % numberChoice(humanNumber)); | |
if (result['winner'] is None): | |
print('Tie!') | |
else: | |
print('%s wins!' % result['winner']); | |
print('Human: %s' % humanScore); | |
print('Computer: %s' % computerScore); | |
print('---') | |
def choiceNumber(choice): | |
return { | |
'rock': 0, | |
'paper': 1, | |
'scissors': 2, | |
}[choice]; | |
def numberChoice(number): | |
return { | |
0: 'rock', | |
1: 'paper', | |
2: 'scissors', | |
}[number]; | |
# start the game | |
startGame(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment