Sep-25-2017, 03:48 AM
(Sep-24-2017, 09:42 AM)buran Wrote: it IS looping, but you never change the value oftoss
in the body of the loop
I don't know why my brain tries so hard to make things harder than they need to be. I was already starting to have the realization that it must have something to do with the
toss
and my loop, but then you confirmed it. After some trial and error, ultimately all I did was add the same line toss = random.randint(1,2)
to the loop itself and Boom! problem resolved. For some reason it didn't occur to me that I needed to add that line inside the loop or that I even could add it to get it to work. Here are new examples.
import random toss = random.randint(1,2) heads = 0 tails = 0 count = 0 print( ''' Welcome to Coin Toss! We\'ll flip a coin 100 times and tell you the results. ''' ) input('\nPress the enter key to continue.') while count != 100: count += 1 toss = random.randint(1,2) if toss < 2: print('You got heads!') heads += 1 if toss > 1: print('You got tails!') tails += 1 print('After 100 tosses?...') print('\nYou got heads', heads, 'times!') print('\nand You got tails', tails, 'times!') print('\nThanks for playing Coin Toss!') input('\n\nPress the enter key to exit.')
Output:You got heads!
You got heads!
You got tails!
You got tails!
You got tails!
You got tails!
You got tails!
You got tails!
You got tails!
You got tails!
You got heads!
You got heads!
You got tails!
You got tails!
You got heads!
You got tails!
After 100 tosses?...
You got heads 47 times!
and You got tails 53 times!
Thanks for playing Coin Toss!
Press the enter key to exit.
Thanks again for the help!! One day I hope to be able to assist someone else rather than always be the one asking for help.
Quote:If you can't learn to do something well?... Learn to enjoy doing it poorly.