Skip to content

Instantly share code, notes, and snippets.

@Kurara
Last active February 22, 2017 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kurara/788c527eb70e7f91b363951160c36a9d to your computer and use it in GitHub Desktop.
Save Kurara/788c527eb70e7f91b363951160c36a9d to your computer and use it in GitHub Desktop.
# Make a two-player Rock-Paper-Scissors game. (Hint: Ask for player plays
# (using input), compare them, print out a message of congratulations to the
# winner, and ask if the players want to start a new game)
# Remember the rules:
# Rock beats scissors
# Scissors beats paper
# Paper beats rock
def checkWhoWin(opt1, opt2):
try:
opn1Int = int(opt1)
opn2Int = int(opt2)
except ValueError:
opn1Int = -1
if (opn1Int == 1):
if (opn2Int == 1):
return 0
elif (opn2Int == 2):
return 2
elif (opn2Int == 3):
return 1
else:
return -1
elif (opn1Int == 2):
if (opn2Int == 1):
return 1
elif (opn2Int == 2):
return 0
elif (opn2Int == 3):
return 2
else:
return -1
elif (opn1Int == 3):
if (opn2Int == 1):
return 2
elif (opn2Int == 2):
return 1
elif (opn2Int == 3):
return 0
else:
return -1
else:
return -1
player1 = input("Player 1, insert name: ")
player2 = input("Player 2, insert name: ")
while(True):
opt1 = input(str(player1) +
" make your move (1:Paper, 2:Scissors, 3:Rock): ")
opt2 = input(str(player1) +
" make your move (1:Paper, 2:Scissors, 3:Rock): ")
result = checkWhoWin(opt1, opt2)
if (result == 1):
print("Player "+player1+" wins")
elif (result == 2):
print("Player "+player2+" wins")
elif (result == 0):
print("Draw")
else:
print("Error")
again = str(input("Play again? (Y/N)"))
if (again.lower() == "n"):
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment