Re: [Tutor] my first project: a multiplication trainer

2008-03-18 Thread Simone
Guba ha scritto: > I was unable to find information on tuple(). (The Python help function > was rather conservative in its output, Google not helpful). > What exactly is the use of tuple(q) here, and why does not a simple q > instead of tuple(q) do? The latter would have been my intuitive > expect

Re: [Tutor] my first project: a multiplication trainer

2008-03-17 Thread Chris Fuller
You should try some of the Python tutorials out there. There's a difference between tuples and lists, and the parameter list passed to the string formatting operator must be a tuple. String formatting will also solve your second problem. Also, the library reference is your friend. I particu

Re: [Tutor] my first project: a multiplication trainer

2008-03-17 Thread Guba
Dear Chris, list, cheers for the great help: very valuable indeed. Chris Fuller wrote: ## for proxyq in choices: q = questions[proxyq] answer = raw_input('%dx%d = ' % tuple(q)) if int(answer) == q[0]*q[1]: print 'correct' else: print 'incorrect'

Re: [Tutor] my first project: a multiplication trainer

2008-03-16 Thread Kent Johnson
tiger12506 wrote: > n = [1,2,5,1,2,34,2,4,7,3,3,45,1,76,8] > proxy = random.shuffle(xrange(len(n))) shuffle() shuffles in place, it doesn't return the shuffled list. > for idx in proxy: > dowith(n[idx]) Why not shuffle n directly? n = ... random.shuffle(n) for x in n: dowith(x) Kent _

Re: [Tutor] my first project: a multiplication trainer

2008-03-16 Thread Chris Fuller
Oops, I based those examples on my initial solution, not the preferred one that preserved the questions. Here is some better code. They only use the shuffle method, and I've elaborated a bit on the basic solution, to illustrate some ideas for improvement. Some things you might try as an exer

Re: [Tutor] my first project: a multiplication trainer

2008-03-16 Thread tiger12506
> choice() returns a random element from the list of choices, not its index. > One could call pop() instead of del, but del is probably a little faster, > and > doesn't return a value that we wouldn't use anyway. pop() wouldn't give > us a > random element, unless passed a random argument, such

Re: [Tutor] my first project: a multiplication trainer

2008-03-16 Thread Chris Fuller
On Sunday 16 March 2008 08:03, Guba wrote: > Hello! > > 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

Re: [Tutor] my first project: a multiplication trainer

2008-03-16 Thread Guba
Hello! 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(

Re: [Tutor] my first project: a multiplication trainer

2008-03-15 Thread Ricardo Aráoz
Kent Johnson wrote: > Ricardo Aráoz wrote: >> Considering the fact that choices[x] == x, > > Only until the first delete (that is not at the end). > >> shouldn't it be : >> del choices[proxyq] > > No. > > Kent > Ooops! Missed that one, sorry.

Re: [Tutor] my first project: a multiplication trainer

2008-03-15 Thread tiger12506
> Considering the fact that choices[x] == x, shouldn't it be : > del choices[proxyq] choices = [9,2,1,3,6,4,7,8,5,0] for idx, x in enumerate(choices): print idx == x False False False True False False False False False False Not always. ___ Tutor

Re: [Tutor] my first project: a multiplication trainer

2008-03-15 Thread Kent Johnson
Ricardo Aráoz wrote: > Considering the fact that choices[x] == x, Only until the first delete (that is not at the end). > shouldn't it be : > del choices[proxyq] No. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/list

Re: [Tutor] my first project: a multiplication trainer

2008-03-15 Thread Kent Johnson
Guba wrote: > Hello everybody, > > I want to create a simple multiplication trainer which quizzes me on the > multiplication table. All multiplication combinations should be asked > once, without repetition. I would - create the list of questions - random.shuffle the list - iterate over the quest

Re: [Tutor] my first project: a multiplication trainer

2008-03-15 Thread Ricardo Aráoz
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 >

Re: [Tutor] my first project: a multiplication trainer

2008-03-15 Thread Chris Fuller
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

Re: [Tutor] my first project: a multiplication trainer

2008-03-15 Thread Alan Gauld
"Guba" <[EMAIL PROTECTED]> wrote > I want to create a simple multiplication trainer which quizzes me on > the > multiplication table. All multiplication combinations should be > asked > once, without repetition. > > Here my pseudo code: > I would very much appreciate if you could comment on/c

[Tutor] my first project: a multiplication trainer

2008-03-14 Thread Guba
Hello everybody, I want to create a simple multiplication trainer which quizzes me on the multiplication table. All multiplication combinations should be asked once, without repetition. Here my pseudo code: ### A = [1,2,3,4,5,6,7,8,9] B = [1,2,3,4,5,6,7,8,9] asked_questions