[Tutor] Random in loop
ryan luna
ryan_gm at sbcglobal.net
Sun Jan 15 02:52:13 CET 2006
Hello, Im kinda stuck on something in the book Python
Programming.
The "Challenage" is to make a progam that flips a coin
100 times and then tells you the number of heads and
tails.
here is what i have so far,
Code:
import random
coin = 0
heads = 0
tails = 0
heads_tails = random.randrange(2)
while coin < 100:
coin += 1
if (heads_tails == 0):
heads += 1
elif (heads_tails == 1):
tails += 1
print coin, heads, tails
raw_input("Enter to exit")
I know what my problem is, i just dont know the how to
fix it.
(Or i could just be writing this wrong all together)
If im even goin at this the right way my problem is i
need to randomly pick a new number at the beggening of
each loop but i dont know how! other then that i think
the rest of the code is good? Thanks for any help ^^
More information about the Tutor
mailing list