[Tutor] Need help solving this problem

2009-06-10 Thread Raj Medhekar
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

Re: [Tutor] Need help solving this problem

2009-06-10 Thread Albert-jan Roskam
+= 1 else: tails += 1 return heads, tails for attempt in range(20): print attempt:, attempt+1, heads:, toss()[0], tails:, toss()[1] --- On Wed, 6/10/09, Raj Medhekar cosmicsan...@yahoo.com wrote: From: Raj Medhekar cosmicsan...@yahoo.com Subject: [Tutor] Need help solving

Re: [Tutor] Need help solving this problem

2009-06-10 Thread Robert Berman
What you are looking at is a simulation whereby a coin having 2 outcomes (heads or tails) is flipped exactly 100 times. You need to tell how many times the coin falls heads up and how many times the coin falls tails up. First become familiar with the random module. Assign a value of 1 for heads

Re: [Tutor] Need help solving this problem

2009-06-10 Thread karma
Hi Raj, 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

Re: [Tutor] Need help solving this problem

2009-06-10 Thread David
Raj Medhekar wrote: 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

Re: [Tutor] Need help solving this problem

2009-06-10 Thread Alan Gauld
Raj Medhekar cosmicsan...@yahoo.com wrote 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

Re: [Tutor] Need help solving this problem

2009-06-10 Thread ayyaz
Raj Medhekar wrote: 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