[Tutor] NEWBIE rolling dice script

Remco Gerlich scarblac@pino.selwerd.nl
Tue, 19 Mar 2002 18:41:26 +0100


On  0, Robert Garber <garber@centralcatholic.org> wrote:
> Hello all,
> 
>  Here is my problem I am working on. I am trying to write a small script that roll dice.  I have written it as a function so I can call it as I need it. When I test the function in the interpreter I get the message listed below. Is this telling my function is working?
> Why doesn't it print out the formatted string.
> After I get this script written I want to use it in an HTML document
> 
> 
> import random
> def rolldice():
>     die1 = random.range(1,7)
>     die2 = random.range(1,7)
>     
>     print "player rolled %d and %d" % (die1, die2,)
> play = rolldice
> >>> play
> <function rolldice at 0180B53C>

When you do 'play = rolldice', that means that 'play' is now the same
function as rolldice is. It doesn't call the function.

Then when you do just 'play', it still doesn't call it, but shows that it's
a function (just like when you do 'x = 3' and then type 'x').

Instead, do

>>> rolldice()

To call the function. The () tell Python to actually run it.

-- 
Remco Gerlich