[Tutor] Question about Python.

T suger_cube at hotmail.com
Wed Mar 25 17:19:35 CET 2009


Hi.
I'm working on Paper, Rock, Scissors in Python.
I need to make it a loop, and test the values (1, 2, 3, /Rock/Paper/Scissors) yet, but i'm kind of stuck. Could you help me?


import random  #Imports the random modual from the library.

def main():  #First function.
    print 'Lets play Paper Rock Scissors!\n'
    print '1 For Rock\n2 For Paper\n3 For Scissors\n4 To Quit'
    number=raw_input ('What do you choose? ') #Gets users input.
    pc = ComputerChoice()
    PlayerChoice(number, pc)

def ComputerChoice(): #Compuers function
    ComputerChoice = random.randrange(1, 4) #Computers random range.
    return ComputerChoice


def PlayerChoice(number, CC): #Uses the users input & compares 
    number = int(number)                             #With the computers.
    print "\n"
    if CC == 1 and number == 3:
        print 'Computer wins: Rock beats Scissors'
    elif CC == 1 and number == 2:
        print 'Player wins: Paper beats Rock'
    elif CC == 2 and number == 3:
        print 'Player wins: Scissors beat paper'
    elif CC == 3 and number == 1:
        print 'Player wins: Rock beats scissors'
    elif CC == 2 and number == 1:
        print 'Computer wins: Paper beats rock'
    elif CC == number:
        print '''Draw!''' #Trying it with 3
    elif CC == 3 and number == 2:
        print 'Computer wins: Scissors beats rock'
    elif number == 4:
        print 'Goodbye'
    else:
        print CC
        print number
    if number != 4:  
        print '\n'
        main()



#Start of program
main()

_________________________________________________________________
Windows Live™ SkyDrive: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_skydrive_032009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090325/1b7e39fd/attachment.htm>


More information about the Tutor mailing list