Forgot to Reply All...

---------- Forwarded message ----------
From: Marc Tompkins <[EMAIL PROTECTED]>
Date: Sat, Mar 15, 2008 at 2:13 AM
Subject: Re: [Tutor] my first project: a multiplication trainer
To: Guba <[EMAIL PROTECTED]>


On Fri, Mar 14, 2008 at 9:43 PM, 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.
> ...

I would very much appreciate if you could comment on/criticise my pseudo
> code. In particular: is my approach correct, or would it be more
> sensible to first generate (or supply?) all possible questions and then
> select the ready questions randomly?
>

Your pseudo code doesn't guarantee that all questions will be asked.  I
think the only way to guarantee that is to generate the list of possibles
first.

Myself, I have a horrible time writing pseudocode  without slipping into
real-code syntax, so please bear with me:

import random    # need this for the randrange() function

possibleQuestions = [(x,y) for x in range(1,10) for y in range(1,10)]
            # list comprehension - creates a list of tuples from (1,1)
through (9,9)
while len(possibleQuestions) > 0:
    question = possibleQuestions.pop(random.randrange
(len(possibleQuestions)))
            # pop() returns the given item and deletes it from list
    (do the rest of your stuff here)

Hope that helps.

-- 
www.fsrtechnologies.com



-- 
www.fsrtechnologies.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to