I've recently been going through "Python Programming, for the Absolute Beginner" Second Edition, By Michael Dawson<br><br>I'm running python 2.5.4 on a windows xp home machine. <br><br>So my question boils down to this:<br>
<br>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.<br><br>I wrote this:<br><br>import random<br>flip = 0<br>
head = 0<br>tails = 0<br><br>while flip != 100:<br>????flip += 1<br>????coin = random.randrange(2)<br>????if coin == 0<br>????????head += 1<br>????elif coin == 1<br>????????tails += 1<br><br>print head, tails<br><br>raw_input("\n<return>")<br>
<br><br>I honestly don't know how code works and would appreciate someone explaining it to me?<br><br>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. <br>
<br>Thanks in advance,<br>Slacker<br>