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
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
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'
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
_
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
> 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
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
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(
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.
> 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
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
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
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
>
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
"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
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
16 matches
Mail list logo