mardi 31 mars 2020

Python how to create a random list only with even numbers?

I'm trying to create a random list with numbers from 0 to 10,000 (inclusive). I need to get a list with even numbers only.

This is my code:

from random import randint

def test(mini, maxx, quantity):
    myl = [randint(mini, maxx) * 2 for i in range(quantity)]
    return myl

print(test(0, 10000, 4))

If I try that, I go past the range of 10000 (because the * 2).

Also, I can only use the randint function.

How do I achieve the desired result?




Aucun commentaire:

Enregistrer un commentaire