[Tutor] NEWBIE rolling dice script

Sean 'Shaleh' Perry shalehperry@attbi.com
Tue, 19 Mar 2002 09:44:25 -0800 (PST)


On 19-Mar-2002 Robert Garber 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>
> 

you never call the function, you assign its name to 'play'.  You need to use ()
to call it:

rolldice() # that is all you need.