[Tutor] complete neophyte question here
srilyk at gmail.com
Mon Oct 12 16:21:12 CEST 2009
On Mon, Oct 12, 2009 at 8:33 AM, Jason Willis <chaoticslacker at gmail.com>wrote:
> 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.
Asking is the first step to understanding. Of course, rather than just
explaining, I'll ask you some questions because if you can explain it you
really know it.
flip = 0
head = 0
tails = 0
What is going on here? What does import random do, and why are you doing it?
while flip != 100:
What is this? What does it do? Is there any other way to do this?
????flip += 1
What's happening here? Why?
????coin = random.randrange(2)
What does this do? Why is it important?
????if coin == 0
????????head += 1
????elif coin == 1
????????tails += 1
What are you doing here? Why are you doing it?
> print head, tails
And what are these for?
I haven't read the book, but I'm sure Dawson gives a good explanation of if
statements and loops.
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor