[Tutor] my first project: a multiplication trainer

Guba listsdl04 at yahoo.de
Sun Mar 16 14:03:25 CET 2008


I like the idea of retaining my original questions by creating a proxy
list, but I wasn't able to understand (find) the proxy list:

Chris Fuller wrote:

> from random import choice

> questions = [ [i,j] for i in range(1,10) for j in range(1,10) ]
> false_answers = []
> choices = range(len(questions))

This I don't understand: len(questions) simply gives 81;
range(len(questions)) counts them all up: 0,1,2...80.

> while choices:
>    proxyq = choice(choices)
here choice(choices) picks ONE item  out of choices (e.g. 56) and
assigns it to proxyq
>    del choices[choices.index(proxyq)]
here the item (56) just assigned to proxyq gets removed from choices
(question: why not use pop() for these last two steps?)
>    q = questions[proxyq]
here q is assigned to item 56, i.e. [7, 3], out of questions (which
contains all 81 possible questions).

Now, because we are operating in a while loop, 81 item are generated and
 81 items are accordingly picked out of the questions list, all this
without repetition of items..

If I am right (am I?) with my interpretation, then I still don't
understand how/where we generated a proxy list... I think we are just
running a while loop without having generated a list out of its ouput!??

Cheers for a short comment!


More information about the Tutor mailing list