At first I had no idea where to start. Finally I tried to get somewhere and I am still stuck. I wrote two different ways using while loop and for loop. Below are codes for both. I am getting errors different places for each loop.
For this code I am getting error at "else" statement.
Someone please help
For this code I am getting error at "else" statement.
Code:
import random
heads = tails = count = 0
while count <= 100:
flip = random.randrange(2)
if flip == 0:
heads += 1
[B]else:[/B]
tails += 1
count += 1
print "The coint landed on heads",heads,'times' \ " and on tails ", tails, 'times'
raw_input ("\nEnd of program...Press enter to exit.")
[B]For this I am getting error at colon on for loop at third line.[/B]
import random
heads = tails = count = 0
[B]for (count != 100):[/B]
flip = random.randrange(2)
if flip == 0:
heads += 1
else:
tails += 1
count += 1
print "The coint landed on heads",heads,'times' \ " and on tails ", tails, 'times'
raw_input ("\nEnd of program...Press enter to exit.")
Comment