Loop problem while generating a new value with random.randint()

Paulo Repreza pxrepreza at gmail.com
Mon Feb 15 17:06:00 CET 2010


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:
        print var, 'equals to:', ranum
    else:
        print var, 'does not equal to:', ranum

########## 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!

Paulo Repreza
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100215/6d7218e8/attachment.html>


More information about the Python-list mailing list