[Tutor] Need help solving this problem
dorjetarap at googlemail.com
Wed Jun 10 23:07:09 CEST 2009
I'm another learner, I used the following:
>>> def toss(n):
heads = 0
for i in range(n):
heads += random.randint(0,1)
return heads, n-heads
>>> print "%d heads, %d tails" % toss(100)
Best of luck in your python endeavors!
2009/6/10 Raj Medhekar <cosmicsand27 at yahoo.com>:
> I have been teaching myself Python using a book. The chapter I am on
> currently, covers branching, while loops and program planning. I am stuck on
> on of the challenges at the end of this chapter, and I was hoping to get
> some help with this. Here it is:
> Write a program that flips a coin 100 times and the tells you the number of
> heads and tails.
> I have tried to think about several ways to go about doing this but I have
> hit a wall. Even though I understand the general concept of branching and
> looping, I have been having trouble writing a program with these. I look
> forward to your reply that will help me understand these structures better.
> Tutor maillist - Tutor at python.org
More information about the Tutor