Advertisement
Guest User

Paper Scissors Rock

a guest
Sep 19th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. options = ["Rock", "Paper", "Scissors"]
  2.  
  3. def RockPaperScissors(p1Choice, p2Choice):
  4.     if p1Choice == p2Choice:
  5.         return 0
  6.     if p1Choice == "Rock":
  7.         return 2 if (p2Choice == "Paper") else 1
  8.     if p1Choice == "Scissors":
  9.         return 2 if (p2Choice == "Rock") else 1
  10.     #p1 must be Paper here
  11.     return 2 if (p2Choice == "Scissors") else 1
  12.  
  13. while True:
  14.     numPlayers = int(input("How many players are there?"))
  15.     if numPlayers >=2:
  16.         playerChoices = [""]*numPlayers
  17.         for player in range(numPlayers):
  18.             while True:
  19.                 playerChoices[player] = input("Player " + str(player + 1) + "?")
  20.                 if playerChoices[player] not in options:
  21.                     print ("Not a vaild input.")
  22.                 else:
  23.                     break
  24.         for player1 in range(1,numPlayers):
  25.             for player2 in range(player1): # so that players don't play twice
  26.                 print ("Player", player2+1,"vs. Player",player1+1,":")
  27.                 result = (RockPaperScissors(playerChoices[player1], playerChoices[player2]))
  28.                 if not result:
  29.                     print ("Tie.")
  30.                     continue
  31.                 if result==1:
  32.                     print ("Player",player1+1,"Wins!")
  33.                     continue
  34.                 print ("Player",player2+1,"Wins!")
  35.     elif numPlayers == 1:
  36.         print ("How sad! Player 1 wins by default.")
  37.     else:
  38.         print ("Not enough players!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement