Timothy Grant wrote:
On Tue, Sep 30, 2008 at 10:20 PM, Pierre Dagenais
<[EMAIL PROTECTED]> wrote:
kayla bishop wrote:
I can't figure out how to write a program where you flip a coin 100 times
and it keeps track of how many heads and tails you flipped but it has to be
random. Can you please help
_________________________________________________________________
Get more out of the Web. Learn 10 hidden secrets of Windows Live.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
------------------------------------------------------------------------
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database:
270.7.5/1698 - Release Date: 29/09/2008 7:25 PM
Here is how one newbie would do it:
import random
# Initialize variables
head = 0
tail = 0
# Flip the coin a hundred times
for x in range(100):
choice = random.randint(1,2)
# Is it 'head'?
if choice == 1 :
head = head + 1
# If not 'head' then it must be tail
else :
tail = tail + 1
print "head = ",head
print "tail = ",tail
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Please let us know if Pierre gets an an "A" on that assignment or not Kayla.
If that's what it is, and I thought it might be, he won't learn how to
program but on exam day he'll realize that cheating is very expensive. A
great lesson to learn early in life if possible. On the other hand if
Kayla is just new to programming and learning on his own, then some
silly mistake can take weeks to figure out and is a huge waste of time,
as I experienced when learning basic on my beloved ZX81. Besides any
teacher worth it's wiff should scan this list for cheaters, right?
Have a nice day, both of you.
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor