mercredi 31 mai 2017

Python comprehension for random floats

import random as rd
print([round(rd.random(), 3) for num in range(20)])

So this prints 20 random numbers shortened to 3 decimals.
How would I write the code so that it writes only random numbers higher than 0.4 but lower than or equal to 1? Any combination of if statements I try yields an error.




Aucun commentaire:

Enregistrer un commentaire