May I suggest running randint using 0, 1. The results can be tested like a boolean. See what happens when you do an if test on 1 versus an if test on 0.
Also perhaps store your results in a dictionary with 'heads', 'tails' each value set to 0. On Sat, May 25, 2013 at 3:13 PM, Steven D'Aprano <st...@pearwood.info>wrote: > On 25/05/13 19:25, Rafael Knuth wrote: > > flips = 0 >> heads = 0 >> tails = 0 >> >> while flips < 10: >> flips = flips + 1 >> > > Don't do this. It's not 1971 any more, we've had for loops for forty years > :-) > > Use while loops when you don't know how many loops you need. When you know > how many loops you will have, use a for loop. > > for flip in range(10): > print(flip) > > will print 0 1 2 3 ... 9 which makes ten loops altogether. If you want to > start counting at 1 instead of 0, use: > > for flip in range(1, 11): > print(flip) > > which will print 1 2 3 ... 9 10. > > > There's no need to count the number of heads and tails separately, since > every loop is guaranteed to give either head or tails. So just count the > number of heads, then the number of tails will be ten less the number of > heads. > > > > > -- > Steven > > ______________________________**_________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> > -- Todd Matsumoto
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor