Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
Re: Loop problem while generating a new value with random.randint
Steve Holden
2/15/2010 4:35:00 PM
Paulo Repreza wrote:
> Greetings,
>
> I'm having problems with a little script that I'm trying to finish, I
> don't know if I'm in the right track but I know somebody is going to
> help me.
>
> The script:
>
> # Import modules random for function randint
>
> import random
>
> # Generating a constant.
>
> var = 65
>
> # Generating a random number.
> ranum = random.randint(1,100)
>
> #Creating while loop. Stops until var == ranum
> while var != ranum:
> if var == ranum:
The "if" condition can never be true, since if it were then the loop
would have just terminated before starting this iteration!
> print var, 'equals to:', ranum
> else:
> print var, 'does not equal to:', ranum
>
Shouldn't there be something here to set ranum to a new value? Otherwise
the same value will be there the next time around ...
> ########## End of Script ###########
>
>
> What I'm trying to do is to print the new value that ranum generates if
> the condition is not met. So far if you run the script it prints the
> same value over and over again, making in an infinite loop. What can I
> do in order to print out the new value generated every time the
> condition is not met?
>
> Thanks!
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010
http://us....
Holden Web LLC
http://www.hold...
UPCOMING EVENTS:
http://holdenweb.event...
d
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: Loop problem while generating a new value with random.randint
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password