I see two things can be changed a little bit.
1. redundant: while, if
2. print style at the last statement.
see below:
#Coin Toss Game
#Zameer Manji
import random
print "This game will simulate 100 coin tosses and then tell you the
number of head's and tails"
tosses = 0
heads = 0
tails = 0
while tosses<100:
coin = random.randrange(2)
tosses +=1
if coin == 0:
heads +=1
print "Heads"
else:
tails +=1
print "Tails"
print "100 tosses have been simulated. Please wait for your results"
print "Out of %s, %s were heads and %s were tails" % (tosses, heads, tails)
cheers,
pujo
On 11/1/05, Zameer Manji <[EMAIL PROTECTED]> wrote:
Ok after looking at everyones replies my program looks like this:
#Coin Toss Game
#Zameer Manji
import random
print "This game will simulate 100 coin tosses and then tell you the
number of head's and tails"
tosses = 0
heads = 0
tails = 0
while tosses<100:
if tosses<100:
coin = random.randrange(2)
tosses +=1
if coin == 0:
heads +=1
print "Heads"
else:
tails +=1
print "Tails"
else:
print "100 tosses have been simulated. Please wait for your results"
print "Out of", tosses, ",", heads, "were heads and", tails, "were tails."
This is the results:
>>> ================================ RESTART
================================
>>>
This game will simulate 100 coin tosses and then tell you the number of
head's and tails
Heads
... (To save space the results have been stripped)
Heads
Out of 100 , 48 were heads and 52 were tails.
Thank you for your help everyone.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
