[Tutor] my first project: a multiplication trainer

Ricardo Aráoz ricaraoz at gmail.com
Sat Mar 15 13:17:35 CET 2008


Chris Fuller wrote:
> The basic approach I use in these sorts of problems is to generate the 
> choices, remove them from a list as they are asked, and then stop when this 
> list is empty.
> 
> 
> If you don't need the list of questions afterwards, this will work:
> 
> from random import choice
> 
> questions = [ [i,j] for i in range(1,10) for j in range(1,10) ]
> false_answers = []
> 
> while questions:
>    q = choice(questions)
>    del questions[questions.index(q)]
> 
>    # stuff
> 
> 
> If you'd like to keep the original question list, make a proxy list, and 
> choose from that:
> 
> questions = [ [i,j] for i in range(1,10) for j in range(1,10) ]
> false_answers = []
> 
> choices = range(len(questions))
> 
> while choices:
>    proxyq = choice(choics)
>    del choices[choices.index(proxyq)]
> 
>    q = questions[proxyq]
> 
>    # stuff
> 

Considering the fact that choices[x] == x, shouldn't it be :
     del choices[proxyq]





More information about the Tutor mailing list