[Tutor] Rock, Paper, Scissors

Jordan Greenberg jordangreenberg at gmail.com
Tue Aug 8 08:00:37 CEST 2006


Christopher Spears wrote:
<SNIP>
> This looks like a fun project to work on.  From
> reading the description, I feel this would be pretty
> straight forward game to program.  However, I have no
> idea how the computer would decide if it wanted a
> rock, paper, or a pair of scissors.  Any hints?


Since theres no real strategy to rock paper scissors, just generate a
random number from 0-2 like this:

import random

random.seed()

choice=random.randint(0, 2)
if choice==0:
	#do whatever for rock
elif choice==1:
	#do whatever for paper
else:
	#do whatever for scissors

That'll take care of the basics for ya. Later you could try and keep
frequency counts over a bunch of trials, see if the human has a
preference, and then weight your response appropriately to try and beat
them ;)

-Jordan Greenberg



More information about the Tutor mailing list