On Fri, May 24, 2013 at 4:54 PM, Rafael Knuth <rafael.kn...@gmail.com>wrote:
> I am writing a program in Python 3.3.0 which flips a coin 10 x times and >> then counts the number of heads and tails. It obviously does something else >> than I intended, and I am wondering what I did wrong: >> > > What is that you intended? > Please explain that. > > I want that program to flip a coin 10 x times and then count the number of > heads and tails. > That's very much it. > Then you have set up the while loop right. It loops 10 times. But if it is a head you are counting heads. Now if it is a tail you are discarding and tossing again! That is the effect of while flips < 10: flips = flips + 1 if random.randint(1,2) == 1: #### - if it is not head? heads = heads + 1 print("We've got " + str(heads) + " heads here." if random.randint(1,2) == 2: #### - this is the second toss I am talking about tails = tails + 1 Now if you replace the second toss by an "else" and count it as a tail you should go towards the code you are looking for. Try it and tell us how it goes. All the best Asokan Pichai
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor