[Tutor] AAAACCCKKK LOOPS :(

Britt A. Green python@experimentzero.org
Sat, 10 Aug 2002 14:06:04 -0700


Let me answer the second question first. Basically a while loop repeats as
long as a condition is true. You could do something like this:

x = 1
while x < 10:
    print x
    x = x+1

This will cause this script to run until x is equal to 10. If you do

while 1:
    <stuff here>

The script will run until you tell it to exit since its always true (1
equals true, btw.) The word break is used to break out of a loop when some
condition is met. In your case it was a random number being less than three.
You can find out more about loops by going here:
http://www.python.org/doc/current/tut/node6.html

As for the sleep command, Python includes a sleep module. To use it, you
need to import the time module. Then call sleep where you want, like so:

time.sleep(number of seconds you want to sleep) So your program would look
like this:

import random, time
while 1:
    mynum = random.randrange(1,13)
    print mynum
    if mynum < 3:
        print "*Click*"
        break
    else:
        print "Your Attempt Failed"
        time.sleep(5) // I'm guess you want to sleep here, after each failed
attempt.



Britt

--
"My mom says I'm cool."

----- Original Message -----
From: "Arie van Willigen" <rellik19@yahoo.com>
To: "Britt A. Green" <python@experimentzero.org>
Sent: Saturday, August 10, 2002 1:53 PM
Subject: Re: [Tutor] AAAACCCKKK LOOPS :(


>
> OK so how would i incorporate a 5 sec sleep mode in between each retry?
> Also how come this works how does the "while" and "break" work???
>  "Britt A. Green"
> wrote:If I understand you right, you want the loop to run until it gets a
one or a
> two, correct? Try something like this:
>
> import random
> while 1:
> mynum = random.randrange(1,13)
> print mynum
> if mynum < 3:
> print "*Click*"
> break
> else:
> print "Your Attempt Failed"
>
> Note: I'm not at a computer with Python installed so the above code may
need
> a bit of tweeking.
>
> --
> "My mom says I'm cool."
> ----- Original Message -----
> From: "Arie van Willigen"
> To:
> Sent: Saturday, August 10, 2002 10:25 AM
> Subject: [Tutor] AAAACCCKKK LOOPS :(
>
>
> >
> > Hi Im having difficulty figuring out how to create a certain loop i
wanted
> to know how whould I have a random number generator continue to spit
> outnumbers until it gets a one or a two. This is my current code:
> >
> > import random
> > mynum = random.randrange(1,13)
> > print mynum
> > if mynum < 3:
> > print "*Click*"
> > else:
> > print "Your Attempt Failed"
> >
> > thank you
> >
> >
> >
> >
> >
> >
> > Me Myself And I... Oh Yeah Arie Too...
> >
> >
> > ---------------------------------
> > Do You Yahoo!?
> > HotJobs, a Yahoo! service - Search Thousands of New Jobs
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
> Me Myself And I... Oh Yeah Arie Too...
>
>
> ---------------------------------
> Do You Yahoo!?
> HotJobs, a Yahoo! service - Search Thousands of New Jobs