[Tutor] complete neophyte question here
Jason Willis
chaoticslacker at gmail.com
Mon Oct 12 15:33:31 CEST 2009
I've recently been going through "Python Programming, for the Absolute
Beginner" Second Edition, By Michael Dawson
I'm running python 2.5.4 on a windows xp home machine.
So my question boils down to this:
At the end of one of his chapters there is a challenge to write a program
that flips a "coin" 100 times then outputs the number of heads or tails it
hit.
I wrote this:
import random
flip = 0
head = 0
tails = 0
while flip != 100:
????flip += 1
????coin = random.randrange(2)
????if coin == 0
????????head += 1
????elif coin == 1
????????tails += 1
print head, tails
raw_input("\n<return>")
I honestly don't know how code works and would appreciate someone explaining
it to me?
Using logic, I shouldn't be able to write the program due to my limited
skills so i don't know how to explain HOW i wrote it because it just sort
of happened. I was sitting home one night and it just came out itself. I
know that's not much of an explanation but there it is.
Thanks in advance,
Slacker
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091012/7e58dda0/attachment.htm>
More information about the Tutor
mailing list