Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- ROCK=0
- PAPER=1
- SCISSORS=2
- TIE=0
- WIN=1
- LOSE=-1
- def createRpsTable():
- rpsTable=list()
- rpsTable.append([None, None, None])
- rpsTable.append([None, None, None])
- rpsTable.append([None, None, None])
- rpsTable[ROCK][ROCK]=TIE
- rpsTable[ROCK][PAPER]=LOSE
- rpsTable[ROCK][SCISSORS]=WIN
- rpsTable[PAPER][ROCK]=WIN
- rpsTable[PAPER][PAPER]=TIE
- rpsTable[PAPER][SCISSORS]=LOSE
- rpsTable[SCISSORS][ROCK]=LOSE
- rpsTable[SCISSORS][PAPER]=WIN
- rpsTable[SCISSORS][SCISSORS]=TIE
- return rpsTable
- def main():
- rpsTable=createRpsTable()
- while True:
- wantsToContinue=runGame(rpsTable)
- if not wantsToContinue:
- break
- def runGame(rpsTable)
- playerChoice=raw_input("Rock, Paper, or Scissors? ").lower()
- while True:
- if playerChoice="rock":
- playerChoice=ROCK
- elif playerChoice="paper":
- playerChoice=PAPER
- elif playerChoice="scissors":
- playerChoice=SCISSORS
- else:
- print "Invalid choice."
- continue
- break
- computerChoice=random.randint(0,2)
- if computerChoice=ROCK:
- print "The computer chose rock."
- elif computerChoice=PAPER:
- print "The computer chose paper."
- else:
- print "The computer chose scissors."
- result = rpsTable[playerChoice][computerChoice]
- if result=WIN:
- print "Congratulations, you win!"
- elif result=LOSE:
- print "Looks like the computer beat you this round."
- else:
- print "It was a tie this time."
- playAgain=raw_input("Do you want to play again? (yes, no)").lower()
- if playAgain in ('y', 'yes'):
- return True
- return False
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment