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

Reply via email to