0

This program is a rock paper scissors simulation. There are two players and each enters r, p or s (lower or upper case). The program then lets the players know who won based on the normal rps rules. There are 5 rounds and it prints the results of each individual game and a running total of games won.

My problem is that it is only evaluating player two as the winner no matter what. I realize a lot of this could be written in a much better way, but I'm just starting out and don't want to change the code too much. I just want it to work. Thanks a lot!

print("Hello!  We're gonna play a few games of Rock, Paper Scissors.")


def rpsGame():
    def rps():

        player1=input('R, P or S?')
        player2=input('R, P or S?')

        if player1==player2:
            return 0
        if (player1==('R'or'r')and player2==('S'or's'))or(player1==('S'or's')and player2==('P'or'p'))or(player1==('P'or'p')and player2==('R'or'r')):
            return 1
        if (player2==('R'or'r')and player1==('S'or's'))or(player2==('S'or's')and player1==('P'or'p'))or(player2==('P'or'p')and player1==('R'or'r')):
            return 2

    result=rps()
    return result


numWinsP1=0
numWinsP2=0


for i in range(5):
    result=rpsGame()
    if result==0:
        print('Nobody wins')
    elif result==1:
        numWinsP1=numWinsP1+1
        print('Player 1 wins.')
    else:
        numWinsP2=numWinsP2+1
        print('Player 2 wins.')
    print("Scores after this play:  Player 1:",numWinsP1,"   Player 2:",numWinsP2)

print('Thanks for playing!')
  • As written, you're only comparing uppercase letters; you're using `or` incorrectly. – Wooble Feb 03 '14 at 23:41
  • 1
    (see http://stackoverflow.com/questions/15112125/if-x-or-y-or-z-blah); can't vote to close as dupe for 14 more minutes. – Wooble Feb 03 '14 at 23:46

1 Answers1

1

Some notes - try using .lower() on the input variable before you start your comparisons... then you can skip the capitization phase.

As written, if rps() doesn't match one of your cases, it doesn't return anything, and if it returns None, you'll hit the Else clause in your main function (causing Player 2 to win).

Your condition that returns "2" will never evaluate- because you copied it from the previous condition without changing it. Therefore 2 will never match...

Your main problem has to be in the comparison row- try eliminating the "or" parts and see if you can get it to work :)

Paul Becotte
  • 9,767
  • 3
  • 34
  • 42
  • The condition that returns 2 is actually changed; player1 and player2 were swapped. The OP's code actually works perfectly if you only input uppercase letters. – Wooble Feb 03 '14 at 23:54
  • Perfect, I wasn't seeing that. Thanks Paul and Wooble! – user3267867 Feb 04 '14 at 01:38