[Tutor] Fixed freezing problem, have new one (fwd)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun Jan 12 15:43:03 2003


Hi Andrew,

Let me forward this to the whole Tutor list; I think you sent a reply just
to me when you actually meant to do a "reply to all".  The questions
you're asking are very much on topic.


I'll try doing a real reply after lunch... *grin* Talk to you later!


---------- Forwarded message ----------
Date: 12 Jan 2003 18:07:52 +0000
From: ahimsa <ahimsa@onetel.net.uk>
To: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] Fixed freezing problem, have new one

I apologise in advance if this is too pedantic or tedious, or takes this
thread too far off course for the original person who posted the query.


On Sun, 2003-01-12 at 10:49, Danny Yoo wrote:

>
> Ok, so say that we start off with:
>
> ###
> def dice(number,sides): #number being the number of times you roll
>     while number > -1 :
>         value = random.randint(0,sides)
>         number = number+1
>         return value,dice(number-2,sides)
> ###
>

Danny, I want to chip in here and pick your brains about this one if I
may :)

Am I correct, in looking at the above code, you are first creating a
module (or function?) called 'dice' that is defined by the parameters of
(a) number of times the dice are 'rolled' and (b) the number of sides of
the dice? If so, why would you need to know the number of sides on a
die, and would this be for one or both dice? And doesn't the number of
sides on a dice stay constant (as in 6)?
The module (or function) then initialises a control structure - the
'while' loop - that sets up the minimum limit as an error control - i.e.
if the dice is not rolled, there can't be any output.
Assuming that the while loop is initialised (i.e. number *is* > -1), the
value is assigned from the calculation on the right side of the '='
sign. Where does one get the 'random.randint' part from? Is that a
module that you imported or is it a keyword that Python recognises? I
can't see it listed as a keyword anywhere though.
Why then would you increment the number through 'number+1'? And, again,
why have the value returned as 'dice(number-2, ...' - why would you
subtract the 2?
I am probably missing a huge chunk here and maybe even muddying the
waters, but I'd find it helpful if you could walk through that a bit
slower.

Much obliged.

Andrew
-- 

________________________%%%%%%%%%%%%%%%%%____________________________

Proudly sent using Ximian Evolution 1.2.1 on a Linux Red Hat 8.0 box.