[Tutor] Python incrementing problem

Stephen Hooker sctjkh at googlemail.com
Thu Oct 11 21:29:01 CEST 2012


Hello, I'm using Python 2.6 to generate switch lists for a model railroad.
I had some help before, possibly from this site but have encountered
another  problem. I realise the code could be better written, but learning
Python is a work in progress. The program works much as expected except
when I try to count & store the results of a random pick from a list of
rolling stock. If I try to store 1 result it works fine. If I try to store
more than 1 result I get one or the other, never both. The code is below
(not the whole program)

This works:

for i in range(1):

pos = random.randrange(0,len(rolling_stock_D))

pick = rolling_stock_D[pos]

for item in noDupes:

if item==pick:

break

else: # else for the loop, executed if the loop ran to exhaustion

noDupes.append(pick)


 for item in noDupes:

print item

print


 if item.find ("SDB") != -1:

SDB_count += 1

if item.find ("DDB") != -1:

DDB_count += 1

--------------------------------------------------------------------

But this doesn't:

for i in range(2):

pos = random.randrange(0,len(rolling_stock_OS))

pick = rolling_stock_OS[pos]

for item in noDupes:

if item==pick:

break

else: # else for the loop, executed if the loop ran to exhaustion

noDupes.append(pick)


 for item in noDupes:

print item

print


 if item.find ("Flat") != -1:

Flat_count += 1

if item.find ("Gondola") != -1:

Gondola_count += 1


Any help would be much appreciated

thank you

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121011/746adce6/attachment.html>


More information about the Tutor mailing list