Skip to content

Instantly share code, notes, and snippets.

@piotrgredowski
Created August 22, 2016 19:51
Show Gist options
  • Save piotrgredowski/335b1e1f02dc886291c0e0c49c798608 to your computer and use it in GitHub Desktop.
Save piotrgredowski/335b1e1f02dc886291c0e0c49c798608 to your computer and use it in GitHub Desktop.
# Rock-Paper-Scissors game for two players
# http://www.practicepython.org/exercise/2014/03/26/08-rock-paper-scissors.html
counter = 1
p_1_c = 0 # number of player 1 wins
p_2_c = 0 # number of player 2 wins
while 1==1:
p_1_x = p_1_c
p_2_x = p_2_c
print ("Hello to Rock-Paper-Scissors.\n It's your game No. " + str(counter) + ".\n You have to type correctly rock, paper, or scissors")
p_1 = input("Player 1, your move:\n")
if p_1 != "rock" and p_1 != "paper" and p_1 != "scissors":
continue
p_2 = input("Player 2, your move:\n")
if p_2 != "rock" and p_2 != "paper" and p_2 != "scissors":
continue
if p_1 == "rock":
if p_2 == "rock":
print ("Draw!")
elif p_2 == "paper":
p_2_c += 1
else:
p_1_c += 1
elif p_1 == "paper":
if p_2 == "rock":
p_1_c += 1
elif p_2 == "paper":
print("Draw!")
else:
p_2_c += 1
else:
if p_2 == "rock":
p_2_c += 1
elif p_2 == "paper":
p_1_c += 1
counter += 1
if p_1_c - p_1_x == 1:
print ("Player 1 wins!")
elif p_2_c - p_2_x == 1:
print ("Player 2 wins!")
else:
print ("Great game, but it was a draw.")
print ("\nP1:\t" + str(p_1_c) + " : " + str(p_2_c) + "\t P2")
a = input("Do you want to start a new game?\ny/n\n")
if a == "y":
continue
elif a == "n":
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment