Im writing a game and want to know how to write the formula for the winner.
So for paper scissors rock, ive written it so the two players enter their choice but i dont know how to write the parameters which show who the winner is.
so paper beats rock, scissors beats paper and rock beats scissors.
what I want is the computer to keep a tally using dictionary to keep score so when one player gets to 5, a winner will be declared.

thanks for reading
crackers

playerScores = {"player1":0, "player2":0}
...
...
if player1 won:
    playerScores["player1"] += 1
elif player2 won:
    playerScores["player2"] += 1

for player in playerScores.keys():
    if playerScores[player] >= 5:
        print player, "won"
        restart game

First line creates a dictionary, pseudo if statements show how you can add 1 onto each players score if they won.

Last section simple iterates through each player in the dictionary, and then checks to see if their score is more than or equal to 5, if it is, then it prints the player won.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.