[Tutor] Fwd: my first project: a multiplication trainer
Marc Tompkins
marc.tompkins at gmail.com
Sat Mar 15 10:15:49 CET 2008
Forgot to Reply All...
---------- Forwarded message ----------
From: Marc Tompkins <marc.tompkins at gmail.com>
Date: Sat, Mar 15, 2008 at 2:13 AM
Subject: Re: [Tutor] my first project: a multiplication trainer
To: Guba <listsdl04 at yahoo.de>
On Fri, Mar 14, 2008 at 9:43 PM, Guba <listsdl04 at yahoo.de> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080315/f121687e/attachment.htm
More information about the Tutor
mailing list