[Tutor] new user question about while loops

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Oct 26 10:12:01 CEST 2005



> >  My goal, create a program that flips a coin 100 times, at the end it
> > says the number of times it flipped heads and flipped tails.
>
> Do you might if we simplify the problem slightly?  Say that you're only
> flipping the coin two times.  Can you write code to say how many times
> it flips heads and tails?  Once you get that working, then modify that
> program to do it for three coins, then four.

Duh: I forgot to add: can you try to do the above without loops?  Since
there's so little coin flipping going on, the code to do this shouldn't be
too long to write, even without loops.

(... although it will get longer for each additional coin we flip.  When
we want to scale our solution to more coins, then that's where loops can
come into play.)



More information about the Tutor mailing list