dimanche 27 décembre 2020

Why is it showing this error: raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population

I'm trying to make two lists with random numbers with random length (they don't have to be the same). Can you tell me why I'm getting this error:

raise ValueError("Sample larger than population or is negative") ValueError: Sample larger than population or is negative

import random
size = random.randint(6,20)
a = list(random.sample(range(1,9),size))
size = random.randint(6,10)
b = list(random.sample(range(1,7),size))
#a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
#b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c = []
for number in a:
    for num in b:
        if(number==num):
            if not number in c:
                c.append(number)
print(a)
print(b)
print(c)



Aucun commentaire:

Enregistrer un commentaire