samedi 28 août 2021

How can a create a random order list and including same numbers?

I want to create five random list but have same and not repeat number from 1-100. I only know I can remove the number from a list which have all number I want and chose randomly put in to new list:

All_list is a list I save all the list I want to save random number from 1-100

number_list is the list including all number I want but it isn't random

number_list = list(range(1, 101))

for i in range(5):
    All_list.append(list)

    for a in range(1,101):
        random_num = random.choice(number_list)
        All_list[i-1].append(random_num)
        number_list.remove(random_num)

But in:

All_list[i-1].append(random_num)

It have a typeError:descriptor 'append' for 'list' objects doesn't apply to a 'int' object. and I don,t know why.

Can anyone help me rewrite this code? I will be appreciate about it.




Aucun commentaire:

Enregistrer un commentaire