[Tutor] Challenge

Che M pine508 at hotmail.com
Tue Sep 22 17:36:42 CEST 2009



> I wrote this code but I know its wrong. Although it works properly:

> flips=0
> h='heads'
> t='tails'
> while True:
>    flips+=1
>    if flips>100:
>        break
>    if True:
>        print(flips,'=',h or t)

> But
it prints every number with the string 'heads'. I'm really blank at
this. It may have 
> something to do with the 'random' module.

Keep in mind, you never import the random module in this code,
so the problem could have nothing to do with that module.  When
you use a module in Python, you import it, and there will be a line
at the top like this:

import random

Read up on importing modules; they are very important (pardon the
pun) in Python.  The random module, like most of the modules, has
lots of functions in it for cases where randomization is needed.  You
can read up on it:  http://docs.python.org/library/random.html

I also really like Effbot's guide to the modules; for example, for random:
http://effbot.org/librarybook/random.htm

Che


_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090922/751d3002/attachment.htm>


More information about the Tutor mailing list