"Jason Willis" <[email protected]> wrote

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:

< ... snipped code ....>

I honestly don't know how code works and would appreciate someone explaining
it to me?

What do you want us to explain?
How you were able to write a working program without actually
kowing how it works? That's probably due to osmosis. You saw
enough similar code that you just coped and modified till it
worked - or seemed to.

Or how the program that you wrote works?
Thats more tricky. What do you not understand?
The book should be explaining how all the individuall bits work.

Your program basically initialises some variables - do you understand
what variables are?

It then repeatedly generates either 0 or 1 for 100 repetitions.
If the number generated is 0 it increments heads. If it is 1 it increments tails.
Then it prints the two stored results.

Which bit of it do you not understand?

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.

Just like great art... :-)

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to