[Tutor] while/if/elif/else loops
Alan Gauld
alan.gauld at freenet.co.uk
Tue Nov 1 07:26:27 CET 2005
> import random
>
>
> while tosses = 100<0:
> coin = randrange(1)
You need to preped random:
coin = random.randrange(1)
Otherwise it looks OKAlthough....
> tosses +=1
> if coin == 0:
> heads +=1
> print "Heads"
You might want to output the count too
print heads, " heads"
Or maybe at the end just print a summary...
HTH,
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list