Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- options = ["Rock", "Paper", "Scissors"]
- def RockPaperScissors(p1Choice, p2Choice):
- if p1Choice == p2Choice:
- return 0
- if p1Choice == "Rock":
- return 2 if (p2Choice == "Paper") else 1
- if p1Choice == "Scissors":
- return 2 if (p2Choice == "Rock") else 1
- #p1 must be Paper here
- return 2 if (p2Choice == "Scissors") else 1
- while True:
- numPlayers = int(input("How many players are there?"))
- if numPlayers >=2:
- playerChoices = [""]*numPlayers
- for player in range(numPlayers):
- while True:
- playerChoices[player] = input("Player " + str(player + 1) + "?")
- if playerChoices[player] not in options:
- print ("Not a vaild input.")
- else:
- break
- for player1 in range(1,numPlayers):
- for player2 in range(player1): # so that players don't play twice
- print ("Player", player2+1,"vs. Player",player1+1,":")
- result = (RockPaperScissors(playerChoices[player1], playerChoices[player2]))
- if not result:
- print ("Tie.")
- continue
- if result==1:
- print ("Player",player1+1,"Wins!")
- continue
- print ("Player",player2+1,"Wins!")
- elif numPlayers == 1:
- print ("How sad! Player 1 wins by default.")
- else:
- print ("Not enough players!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement