Python: Rock Paper Scissors While Loop Issue
Question: I'm having an issue with my programming of Rock, Paper, Scissors for Python.
My issue occurs when there is a tie. When there is a tie, my program is
supposed to going into a while loop within the if statement of the tie and
reask the player the same question, rock, paper or scissors again until it
breaks out of the tie. I have attached the link to the image of the issue:

![](http://i.imgur.com/GNKJiNY.png?2)

In Round 5: you can see the issue.

I am taking an intro to programming class so I'm still a beginner and I do not
know what I am doing wrong.

# A Python program for the Rock, Paper, Scissors game.

    
    
    import random
    
    def rock_paper_scissors():
    playerscore = 0
    computerscore = 0
    rounds = input('\nHow many points does it take to win?: ')
    count = 1
    while playerscore or computerscore != int(rounds):
        print('\n********************* ROUND #',count,'*********************')
        player = input('\nPick your throw: [r]ock, [p]aper, or [s]cissors?: ')
        computerthrow = random.randint(0,2)
        if (computerthrow == 0):
            computer = "rock"
            computer = 'r'
        elif (computerthrow == 1):
            computer = "paper"
            computer = 'p'
        elif (computerthrow == 2):
            computer = "scissors"
            computer = 's'
        if (player == computer):
            print('Tie!')
            while (player == computer):
                player = input('\nPick your throw: [r]ock, [p]aper, or [s]cissors?: ')
                computerthrow = random.randint(0,2)
                if (computerthrow == 0):
                    computer = "rock"
                    computer = 'r'
                elif (computerthrow == 1):
                    computer = "paper"
                    computer = 'p'
                elif (computerthrow == 2):
                    computer = "scissors"
                    computer = 's'      
                print(computer)
        elif (player == 'r'):
            if (computer == "p"):
                print('Computer threw paper, you lose!')
                computerscore=computerscore+1
            else:
                print('Computer threw scissors, you win!')
                playerscore = playerscore+1
            #count = count + 1
        elif (player == 'p'):
            if (computer == "r"):
                print('Computer threw rock, you win!')
                playerscore = playerscore+1
            else:
                print('Computer threw scissors, you lose!')
                computerscore=computerscore+1
            #count = count + 1
        elif (player == 's'):
            if (computer == "p"):
                print('Computer threw paper, you win!')
                playerscore = playerscore+1
            else:
                print('Computer threw rock, you lose!')
                computerscore=computerscore+1
        count = count + 1
        print('\nYour score: ',playerscore)
        print('Computer''s score: ',computerscore,'\n')
    print('********************* GAME OVER ********************')
    
    def main(): 
    print('ROCK PAPER SCISSORS in Python')
    print()
    print('Rules: 1) Rock wins over Scissors.')
    print('       2) Scissors wins over Paper.')
    print('       3) Paper wins over Rock.')
    
    rock_paper_scissors()
    
    main()
    


Answer: Your problem comes from the way you have structured your control statements
(if, elif, else). When you enter your tie while loop, you are constantly
running it until someone wins and that looks like it works no problem. The
issue is that once you do that, the python interpreter skips all elif and else
statements in that control block (if I say if x == 3: do this else: do that) I
don't want python to follow through with the else condition if x does indeed
== 3). Sorry if that is confusing, long story short you need to make sure that
even when your tie block gets executed you still move on to scoring the round
and starting a new one. The easy way to do that is just change the elif
(player == "r") to an if statement. That way the interpreter treats the
scoring control sequence as its own block and it will always be executed once
you assign the throws each player makes.

# Example:

    
    
    def f(x):
        if (x == 0):
            print("1")
            x += 1
        elif (x == 1):
            print("2")
        print("Done!")
    
    def g(x):
       if (x == 0):
           print("1")
           x += 1
       if (x == 1):
           print("2")
       print("Done!")
    

if you call f(0): Python will print out 1 and then Done!

if you call g(0): Python will print out 1 then 2 then Done!

