[Tutor] results not quite 100 percent yet
Alan Gauld
alan.gauld at btinternet.com
Wed Jan 30 09:35:29 CET 2008
"bhaaluu" <bhaaluu at gmail.com> wrote
In addition to Kents comments about dictionaruy
access I think there may be another problem in
your logic.
> The first loop is supposed to populate G with
> a random range of 4 integers 10 to 109
> in random keys 1-19 that have a zero (except keY 6 and keY 11)
> So keY 6 and keY 11 should both have a zero in G after the
> four integers have been sown.
>
> if keY == 6 or keY == 11 or tablE.values()[keY-1][6] != 0:
> tablE.values()[5][6] = 0
> tablE.values()[10][6] = 0
> cnt -= 1
> keY = random.choice(a)
This detects any of the exception cases so a simple else
clause should be sufficient for the others. However if you
really want an explicit check...
> if keY != 6 or keY != 11 or table.values()[keY-1][6] == 0:
This test should use 'and' rather than 'or' since you want
all of the conditions to be true, not just one of them.
But since the failing condituions should all have been
caught above simply using else here would do what
I think you want.
> b = range(10,110) # 10 to 109
> integer = random.choice(b)
> tablE.values()[keY-1][6] = integer
> cnt += 1
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list