T wrote:
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

In ComputerChoice(), you obtain the choice of the computer.
In PlayerChoice() however, you do not obtain the player choice, but instead decide on the result.

I would suggest to modify PlayerChoice() to just obtain the player choice (code which you now have in main()).

Next write a new function that takes the computer choice and the player choice, and decides on the outcome.
(that function should have 3 possible return values).

Then in the main loop combine all three functions.
The construct you should investigate seems the 'while' statement.
(while the game is not decided, call the functions)


Sincerely,
Albert
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to