1st non-trivial program - gentle criticism requested

Emile van Sebille emile at fenx.com
Thu Apr 13 08:53:56 EDT 2000


Paul,

Just a few observations I have along the lines of
'oh!, you mean this' as I read your code.


>>> a = [0,0,0,0,0,0]
>>> for i in xrange(10000):
 j = int(whrandom.choice('012345'))
 a[j]=a[j]+1


>>> print max(a)
1719
>>> a.index(max(a))
3
>>>

HTH,

Emile van Sebille
emile at fenx.com
-------------------


----- Original Message -----
From: Paul-Michael Agapow <p.agapow at ic.ac.uk>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, April 13, 2000 1:10 AM
Subject: 1st non-trivial program - gentle criticism requested


>
> Hi y'all,
>
> I'm experimenting with Python for a number of purposes (an embedded
> language for simulations, a tool for exploring experimental data, a
good
> first programming language) and so I've cobbled together my first
> non-trivial program. With some trepidation, I post it here in the
hopes
> that experts will be able to coach me in "The Python Way". I realise
it
> looks like C++ (my usual langauge), but criticisms of style would be
> useful too.
>
> Basically, it's a recreation of the "Methinks it is a weasel"
simulation
> detailed by Richard Dawkins in "The Blind Watchmaker". A population of
> strings is compared vs. a target string and the "fittest" (the one
that
> most resembles the target) is used to form the next generation, with a
> small chance. So it's a simple genetic algorithm.
>
> thanks
>
> p-m
>
>
> --- program follows
<snipped>






More information about the Python-list mailing list