# play rock, s, p game again
# this time we make sure the user gives a valid input
# the game stops when the user quits

# get the random functions
import random

picking=True # used for the while loop

while picking: # the loop stops when the user quits (by selecting "q")

    # let user pick
    print ("\nlet's play rock, scissor, and paper!")
    user = raw_input("choose rock (r), scissors(s), paper(p) or quit(q)")

    # let computer choose 
    # 1: rock, 2: scissor, and 3: paper
    number = random.randrange(1,4)
    if number == 1:
        computer="r"
    elif number == 2:
        computer="s"
    else :
        computer="p"

    print "your input is", user

    if user=="q": # user wants to quit
        print "\ngame over, have a nice day!"
        picking=False # important line, the user decides to quit
    elif user!="r" and user!="s" and user!="p": # check if it is an allowed input
        print user,"is not an allowed input!"
    else: # an allowed input and not quit
        if user==computer:  # tie, play again
            print "tie, let's play again!"
        else: # not a tie and a valid input
            print "computer's input is",computer
            if computer=="r": # computer is rock
                if user =="s":
                    print "You lose!"
                else:
                    print "you win!"
            elif computer=="s": #computer is scissor
                if user =="p":
                    print "You lose!"
                else:
                    print "you win!"
            else: # computer is paper
                if user =="r":
                    print "You lose!"
                else :
                    print "you win!"


raw_input("press enter to exit.")

