i have to write a rock paper scissors program in python, but every time i run my code...

def rockPaperScissors():
    import random
    computerIndex = random.randint(1,3)
    if computerIndex == 1:
        computer = "rock"
    elif computerIndex == 2:
        computer = "scissors"
    else:
        computer = "paper"
    player = raw_input("rock, paper or scissors :")
    if player[0] != "r" or player[0] != "p" or player[0] != "s":
        print "incorrect choice entered"
    elif computer == "rock" and player == "rock":
        print "its a draw"
    elif computer == "rock" and player == "paper":
        print "player wins"
    elif computer == "rock" and player == "scissors":
        print "computer wins"
    elif computer == "scissors" and player == "rock":
        print "player wins"
    elif computer == "scissors" and player == "paper":
        print "computer wins"
    elif computer == "scissors" and player == "scissors":
        print "its a draw"
    elif computer == "paper" and player == "rock":
        print "computer wins"
    elif computer == "paper" and player == "paper":
        print "its a draw"
    elif computer == "paper" and player == "scissors":
        print "player wins"

i get an error. not an actual error, its just that everytime i try to input my choice, the incorrect choice entered line comes up. im at a loss. im sure ive made some silly mistake somewhere, but can anyone spot it, because ive been staring at it for an hour now and i cant :(

Recommended Answers

All 3 Replies

if player[0] != "r" or player[0] != "p" or player[0] != "s":
        print "incorrect choice entered"

Just a minor logic error. This should be:

if player[0] != "r" and player[0] != "p" and player[0] != "s":
        print "incorrect choice entered"

oh man cheers, heh i feel kinda stupid now.
thanks a bunch

This might be easier to understand ...

if player[0] not in 'rps':
        print "incorrect choice entered"
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.