Skip to content

Instantly share code, notes, and snippets.

@DivinityArcane
Created March 1, 2018 14:54
Show Gist options
  • Save DivinityArcane/79d63cafca4167a7d660d0d3024a0a18 to your computer and use it in GitHub Desktop.
Save DivinityArcane/79d63cafca4167a7d660d0d3024a0a18 to your computer and use it in GitHub Desktop.
import random
print("Let's play some Rock, Paper, Scissors!")
options = ['rock', 'paper', 'scissors']
trumps = {'rock': ['scissors'], 'paper': ['rock'], 'scissors': ['paper']}
wins = 0
losses = 0
running = True
while running:
option = input("What do you choose?: ")
if option not in options:
print('You must choose between ' + ', '.join(options))
continue
cpuOption = options[random.randrange(len(options))]
print("You chose " + option + " while the computer chose " + cpuOption)
if option == cpuOption:
print("It's a tie! No one wins! Try again...")
print("\n") # move down a line for readability
continue
won = False
if cpuOption in trumps[option]:
won = True
if won:
print("You win! Congratulations! Let's try again...")
wins += 1
else:
print("You lose! Better luck next time! Let's try again...")
losses += 1
print("You've won %d time(s) and lost %d time(s)." % (wins, losses))
print("\n") # move down a line for readability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment