Re: [Tutor] Modifying game of life

2005-01-10 Thread Kent Johnson
 if randval > perc:
 EMPTY <= you don't need the lines like this, they don't do anything
 return EMPTY
And you can test for less-than-or-equal in one test
 elif randval <= perc:
 return PERSON
in fact since one of the tests has to be true you can just use else:
 if randval > perc:
 return EMPTY
 else:
 return PERSON
Kent
Kooser, Ara S wrote:
Kent and Max. Thank you very much. It works fine now. 

Ara

perc = raw_input("Please enter a threshold between 0-1.  ")
perc = float(perc)
def percolation(perc):
randval = random.random()
print randval
PERSON, EMPTY = '*', '.'
if randval > perc:
EMPTY
return EMPTY
elif randval < perc:
PERSON
return PERSON
elif randval == perc:
PERSON
return PERSON
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Modifying game of life

2005-01-10 Thread Kooser, Ara S
Kent and Max. Thank you very much. It works fine now. 

Ara



perc = raw_input("Please enter a threshold between 0-1.  ")
perc = float(perc)

def percolation(perc):
randval = random.random()
print randval
PERSON, EMPTY = '*', '.'
if randval > perc:
EMPTY
return EMPTY
elif randval < perc:
PERSON
return PERSON
elif randval == perc:
PERSON
return PERSON


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Modifying game of life

2005-01-10 Thread Kent Johnson
Kooser, Ara S wrote:
I was trying to modify the Game of Life to a percolation model (you can
pick what the probability of each point being occupied). I wrote the def
for the percolation however when I print the world all I get is 
NONE NONE NONE NONE 
Etc...

I know my problem is in the line  world[i, j] = percolation(perc). The
original code that Danny wrote had the line
world[i,j]= random.choice([LIVE,DEAD]). I am guessing that Danny's code
give a 50/50 chance of a site being occupied and assigns that to i,j . I
do not have the correct syntax to make the world[i,j] go through the
percolation def. I think i and j are not getting assigned a value.
Does anyone have an suggestions, explanations, websites? Thanks. 

Ara

import random
perc = raw_input("Please enter a threshold between 0-1.  ")
Here perc will be a string. You need to convert it to a float using
perc = float(perc)
Kent
raw_input("Press return to make a world")
PERSON, EMPTY = '*', '.'
def percolation(perc):
randval = random.random()
PERSON, EMPTY = '*', '.'
if randval > perc:
EMPTY
if randval < perc:
PERSON

def make_random_world(M, N):
world = {}
for j in range(N):
for i in range(M):
world[i, j] = percolation(perc)
world['dimensions'] = (M, N)
return world

def print_world(world):
M, N = world['dimensions']
for j in range(N):
for i in range(M):
print world[i, j],
print
print_world(make_random_world(10, 10))
###
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Modifying game of life

2005-01-10 Thread Max Noel
On Jan 10, 2005, at 17:53, Kooser, Ara S wrote:
Does anyone have an suggestions, explanations, websites? Thanks.
Ara

import random
perc = raw_input("Please enter a threshold between 0-1.  ")
raw_input("Press return to make a world")
PERSON, EMPTY = '*', '.'
def percolation(perc):
randval = random.random()
PERSON, EMPTY = '*', '.'
if randval > perc:
EMPTY
if randval < perc:
PERSON
	I think the problem is there. The function doesn't return anything. 
Chances are you should use "return EMPTY" and "return PERSON" instead 
of what you have right now (have you been using Ruby recently?).
	Also, the function still doesn't return anything when randwal == perc.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor