I am confused. It looks to me as if the while loop will never work, because it stays inside while <100 and further down in the loop, if it is < 100, it should go out of the loop. How can it stay running while <100 and yet go out if  < 100?

Johan
 

Nick Eberle wrote:
print "This is a coin flip game"
 
print "\n100 flips will be made and it will show the amount of times heads or tails came up"
 
import random

#assigning variables to track the amount of times heads or tails comes up
heads=0
tails=1
 
flip=100
while flip < 100:
    flip -= 1
    random.randrange(2)
    if flip < 100:
        break
 
print "\nThe amount of times tails came up was" , tails , "The amount of times heads came up was" , heads
 
raw_input()


From: bob [mailto:[EMAIL PROTECTED]]
Sent: Tue 10/25/2005 10:58 PM
To: Nick Eberle; tutor@python.org
Subject: Re: [Tutor] new user question about while loops

At 10:53 PM 10/25/2005, Nick Eberle wrote:
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
        boundary="----_=_NextPart_001_01C5D9F1.A836CF4F"

Sorry for potential double post, error with first send
----------------------------------------------------------------------
Hello all,
 
I had a new question about python. I am pretty much in tutorial learning stages, but attempting to create sample programs not in my book to learn how to construct scripts.
 
I understand the format of while loops, but is it possible to use the random.randrange function in them?
 
My goal, create a program that flips a coin 100 times, at the end it says the number of times it flipped heads and flipped tails.
 
My dilemia, how do I get this to work with a while loop? I tried intially assigning
 
heads=0
tails=1
 
then I figured I could just do a while loop and then use the random function each time. At the end it could count the number of times the random generated a 0 or a 1.
 
However I can't seem to construct it in a way that makes or works.

Show us your code, as flawed as it might be. Then we can advise you.

_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to