Sep-24-2017, 09:09 AM
Hello all,
I don't know if I should be adding my issue to this thread or starting a new one. I too am having trouble with my coin flip/toss game but my issue is a little different.
I was asked to create a game that 'tosses' a coin 100 times and then displays the results for how many times it landed on each side. I seem to be able to get the game to work in that it's tossing it 100 times and displaying the results, but my problem is that it doesn't seem very random. All I've been able to get is 100 heads or 100 tails. Never any mix of the 2. I've messed around with this and tried several different things such as changing the range of numbers, i.e.
toss < 2 instead of toss == 1
I tried setting the randint range from 1,2 to 0,1
I even tried expanding the range to 1, 10 and using if toss < 5, then heads +=1
Nothing I have tried seems to alter my results. I've been racking my brain trying to figure this out and I can't. I've searched through the help files in python on the random module and tried to search on google for more info. Basically I'm trying to let you all know that I've done all I can to find the answer on my own before coming to ask you. As always I appreciate any input you can offer.
below are my code and output examples
I don't know if I should be adding my issue to this thread or starting a new one. I too am having trouble with my coin flip/toss game but my issue is a little different.
I was asked to create a game that 'tosses' a coin 100 times and then displays the results for how many times it landed on each side. I seem to be able to get the game to work in that it's tossing it 100 times and displaying the results, but my problem is that it doesn't seem very random. All I've been able to get is 100 heads or 100 tails. Never any mix of the 2. I've messed around with this and tried several different things such as changing the range of numbers, i.e.
toss < 2 instead of toss == 1
I tried setting the randint range from 1,2 to 0,1
I even tried expanding the range to 1, 10 and using if toss < 5, then heads +=1
Nothing I have tried seems to alter my results. I've been racking my brain trying to figure this out and I can't. I've searched through the help files in python on the random module and tried to search on google for more info. Basically I'm trying to let you all know that I've done all I can to find the answer on my own before coming to ask you. As always I appreciate any input you can offer.
below are my code and output 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 if toss < 2: print('You got heads!') heads += 1 else: 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 tails!
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 tails!
You got tails!
You got tails!
You got tails!
You got tails!
You got tails!
After 100 tosses?...
You got heads 0 times!
and You got tails 100 times!
Thanks for playing Coin Toss!
Press the enter key to exit.
ANDOutput:You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
You got heads!
After 100 tosses?...
You got heads 100 times!
and You got tails 0 times!
Thanks for playing Coin Toss!
Press the enter key to exit.
Quote:If you can't learn to do something well?... Learn to enjoy doing it poorly.