0

I was bored so i created this program ti simulate a game of paper, scissors, rock.
It was working well untill idecided to tinker a-bit.
Now when I run it and enter a move it outputs this:

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Choose your move  paper
You chose paper
Choose your move  scissors
You chose scissors
Choose your move  rock
You chose rock
Choose your move  

Here is the code:

import random
playagain = "yes"
quitgame = "no"

#Ask if user would like to play again
#Replay game if user would like to continue
while (playagain == "yes" or playagain == "y" and quitgame == "no" or quitgame == "n"):

    playermove = "--"

    #Choose moves
    while (playermove != "paper" or playermove != "scissors" or playermove != "rock"):
        playermove = str(input("Choose your move  "))
        playermove = playermove.lower()
        if (playermove == "paper" or playermove == "scissors" or playermove == "rock"):
            print ("You chose", playermove)
        else:
            print("Please choose a valid move!")

    compmove = random.randint(0,2)
    if (compmove == 0):
        print ("Computer chose paper")
    elif (compmove == 1):
        print ("Computer chose scissors")
    elif (compmove == 2):
        print ("Computer chose rock")

    #Work out winner
    #0 = paper
    #1 = scissors
    #2 = rock

    #If user plays paper
    if (playermove == "paper" and compmove == 0):
               print ("Draw")
    elif (playermove == "paper" and compmove == 1):
               print ("You lose!")
    elif (playermove == "paper" and compmove == 2):
               print ("You win!")

    #If user plays scissors
    if (playermove == "scissors" and compmove == 0):
               print ("You win!")
    elif (playermove == "scissors" and compmove == 1):
               print ("Draw")
    elif (playermove == "scissors" and compmove == 2):
               print ("You lose!")

    #If user plays rock
    if (playermove == "rock" and compmove == 0):
               print ("You lose!")
    elif (playermove == "rock" and compmove == 1):
               print ("You win!")
    elif (playermove == "rock" and compmove == 2):
               print ("Draw")

    playagain = str(input("Would you like to play again?  "))
    playagain = playagain.lower()
    quitgame = str(input("Do you really want to quit?  "))

exit()

Any help greatly appreciated.

2
Contributors
2
Replies
32
Views
1 Year
Discussion Span
Last Post by Gribouillis
1

I solved it,

The second while loop needed and instead of or because it checks for one of the three parameters not all three.

Votes + Comments
good
1

You can also use

while playermove not in ('paper', 'scissors', 'rock'):
    ...

Edited by Gribouillis

Votes + Comments
I might use this, if would probably be more efficient, thank-you
This question has already been answered. 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.