Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python
[NEWB]: List with random numbers
 

Index | Next | Previous | View Flat


acachinero at gmail

Aug 19, 2006, 11:14 PM


Views: 228
Permalink
[NEWB]: List with random numbers

Hey all,

I'm trying to write a program in Python for learning purposes which is
meant to:

Generate a random number from 0 to 6
Insert this random number to the end of a list unless the number is
already there
finish with a len(list) = 7

so far, I have this:

import random

random_list = []

while len(random_list) < 8:
j = random.randrange(6)
if (j in random_list):
continue
else:
random_list.append(j)
continue

print random_list


however, I get stuck in an infinite loop.

Any suggestions?

Thank you in advance,

Adri

--
http://mail.python.org/mailman/listinfo/python-list

Subject User Time
[NEWB]: List with random numbers acachinero at gmail Aug 19, 2006, 11:14 PM
    Re: [NEWB]: List with random numbers faulkner612 at comcast Aug 19, 2006, 11:23 PM
    Re: [NEWB]: List with random numbers rogue_pedro at yahoo Aug 19, 2006, 11:28 PM
    Re: [NEWB]: List with random numbers bj_666 at gmx Aug 19, 2006, 11:32 PM
        Re: [NEWB]: List with random numbers acachinero at gmail Aug 19, 2006, 11:40 PM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.