0

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

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by a1eio
0
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.