Q:

How do I keep score in a rock paper scissors game?

I'm just starting Python and writing a simple rock paper scissors game. Here's what I have so far. I can play a game with another player perfectly. What I want to know is how to keep score of the wins, so if Player 1 wins the first game it would say:
Player 1 = 1
Player 2 = 0
And so on. Also if there's any tips to make my code more efficient (with a nice explanation), that would be nice.
Thanks!

A:

Consider this pseudo-code for suggestions (some parts need to be implemented):
# a Player class. it should have a Name and a Score
class Player():
   def __init__(name):
      self.name = name
      self.score = 0

# displays a prompt and reads in the players name returning a string
def getPlayerName():
   # needs code here, see next function for idea of what
   pass

# ask the player to make a choice, takes a Player object
# and returns a string
def getPlayerAttack(player):
    print "%s, what do you choose?" % player.name
    return raw_input("> ")

# determines who wins and updates score accordingly
# takes in the player objects and their attack choices
def attack(player1, choice1, player2, choice2): 
    if choice1 == choice2:
       print "Its's a tie."
    elif choice1 == "1" and choice2 == "2":
       print "%s wins." % player2
       player2.score = player2.score + 1
    elif ... # other attacks

# display the scores of the two players
def displayScores(player1, player2):
    print "%s vs %s" % (player1.score, player2.score)

player1 = Player(getPlayerName())
player2 = Player(getPlayerName())
while true:
    choice1 = getPlayerAttack(player1)
    choice2 = getPlayerAttack(player2)
    attack(player1, choice1, player2, choice2)
    displayScores(player1, player2)

This will need some work, and it's not super-optimal, but it should be a start and should show some more concepts. Use Ctrl-C to stop or add a stop condition (e.g. either player enters "0") -- bugs included for free. :) 
Happy coding.

